Saturday, 12 August 2017

Java Program to read and print an integer value.

In this program we will read an integer value and print the value, by using this example we will learn how to read values from the keyboard?

Read and Print an Integer using Java Program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.lang.*;
import java.util.*;
class j3{
        public static void main(String args[])
        {
                int a;
                Scanner buf=new Scanner(System.in);
                System.out.print("Enter value of a :");
                a=buf.nextInt(); /*nextInt() method of Scanner class*/
                System.out.println("Value of a:" +a);
        }
}
    Complie  : javac j3.java
    Run  : java j3
    Output
    Enter value of a :120 
    Value of a:120 
    

No comments:

Post a Comment