Premium Only Content

How to Print an Integer entered by a user | Java Examples
In this program, you'll learn to print a number entered by the user in Java. The integer is stored in a variable using System.in, and is displayed on the screen using System.out.
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().
-
16:29
Sideserf Cake Studio
5 hours ago $1.77 earnedThis Cruise Ship Is A CAKE!
24K5 -
14:49
Clownfish TV
20 hours agoNintendo Switch 2 BACKLASH! Gamers BOYCOTT Over Pricing?!
16.9K8 -
24:17
JasminLaine
19 hours agoCTV Reporter DESTROYS Carney By Quoting His BOOK—His INSANE Answer STUNS Host
22.7K26 -
24:47
World2Briggs
1 day ago $1.04 earned10 Cities Where The High Cost Of Living Just Isn't Worth It
15.3K5 -
LIVE
SoundBoardLord
4 hours agoSaturday Variety Gaming with Friends!!
142 watching -
8:35
ARFCOM News
23 hours ago $0.44 earnedThis Is How We End The NFA | Booker's Hypocrisy | ATF Facial Recognition
12.7K4 -
10:51
IsaacButterfield
1 day ago $0.99 earnedToddler Expelled From School For Being “Transphobic”
13.2K8 -
24:52
Degenerate Jay
22 hours ago $0.18 earnedIs Marvel Ruining Venom Now? Why Is Mary Jane Venom?
7.84K4 -
2:11:46
Rotella Games
5 hours agoSaturday Morning Family Friendly Fortnite
14.2K3 -
1:10:16
Squaring The Circle, A Randall Carlson Podcast
5 hours agoEP043-PT2: A Biographical Look Into The Life of Randall Carlson With Guest Warren Steury
4.42K2