In this example you will learn how to read an integer value in java.
Java Code: Write a program to how to read an integer value in java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public static void main(String[] args) { // input from standard input - keyboard Scanner reader = new Scanner(System.in); System.out.print("Enter a number: "); // nextInt() reads the next integer from the keyboard int number = reader.nextInt(); // println() prints the following line to the output screen System.out.println("You entered: " + number); } |
Output:
In this example you have learned how to read an integer value in java