Print an Integer given by user

In this example, we are giving a program to Print an Integer given by an user.


To print an Integer given by user:

  1. # To print an Integer given by user
  2. public classimport java.util.Scanner;
  3. class HelloWorld {
  4. public static void main(String args[]) {
  5. Scanner reader = new Scanner(System.in);
  6. System.out.print("Enter a number: ");
  7. int number = reader.nextInt();
  8. System.out.println("You entered: " + number);
  9. }
  10. }

Output:

Enter a number: 73
You entered: 73