Ads

How to read and print an integer value in Java ? | JAVA PROGRAMMING | JAVA LANGUAGE

 Here, we will learn how to take an integer input from user and print on the screen, to take an integer value's input - we use Scanner class, for this we have to include java.util.* package in our Java program.



import java.util.*;


class j3 {

    public static void main(String args[]) {

        int a;


        //declare object of Scanner Class

        Scanner buf = new Scanner(System.in);


        System.out.print("Enter value of a :");

        /*nextInt() method of Scanner class*/

        a = buf.nextInt();


        System.out.println("Value of a:" + a);

    }

}

Post a Comment

0 Comments