The given task is to take an integer as input from the user and print that integer in Java language.
In below program, the syntax and procedures to take the integer as input from the user is shown in Java language.
- The user enters an integer value when asked.
- This value is taken from the user with the help of nextInt() method of Scanner Class. The nextInt() method, in Java, reads the next integer value from the console into the specified variable.
variableOfIntType = ScannerObject.nextInt(); where variableOfIntType is the variable in which the input value is to be stored. And ScannerObject is the beforehand created object of the Scanner class.
- This entered value is now stored in the variableOfIntType.
- Now to print this value, System.out.println() or System.out.print() method is used. The System.out.println() method, in Java, prints the value passed as the parameter to it, on the console screen and the changes the cursor to the next line on the console. Whereas System.out.print() method, in Java, prints the value passed as the parameter to it, on the console screen and the cursor remains on the next character of the last printed character on the console.
- Hence, the integer value is successfully read and printed.
Enter the integer: 10 Entered integer is: 10
- How to Read and Print an Integer value in C
- How to Read and Print an Integer value in C++
- Java Program to Print a Square Pattern for given integer
- Program to Convert Set of Integer to Array of Integer in Java
- How to read a Matrix from user in Java?
- How to make an ArrayList read only in Java
- CharArrayReader read() method in Java with Examples
- Reader read() method in Java with Examples
- ObjectInputStream read() method in Java with examples
- Ways to read input from console in Java
- StringReader read() method in Java with Examples
- Image Processing in Java | Set 1 (Read and Write)
- CharBuffer read() methods in Java with Examples
- PushbackReader read() method in Java with Examples
- CharArrayReader read(char) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.