Java Program to Print an Integer (Entered by the User) - safetxt
avatar
Java Program to Print an Integer (Entered by the User)

mrt481 454 28th Aug, 2022

Java 0.56 KB
Loading Please wait...
Description

In this program, an object of Scanner class, reader is created to take inputs from standard input, which is keyboard. Then, Enter a number prompt is printed to give the user a visual cue as to what they should do next. reader.nextInt() then reads all entered integers from the keyboard unless it encounters a new line character \n (Enter). The entered integers are then saved to the integer variable number. If you enter any character which is not an integer, the compiler will throw an InputMismatchException. Finally, number is printed onto the standard output (System.out) - computer screen using the function println().


Recent Pastes

Please disable your adblock and script blockers to view this page