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().
-
22:47
The Pascal Show
1 day ago $0.15 earnedTHEY’RE HIDING EVIDENCE?! Candace Owens EXPOSES Foreign Connection In Charlie Kirk Shooting
31.2K34 -
7:44:50
SpartakusLIVE
9 hours agoThe Duke of Nuke CONQUERS Arc Raiders
163K2 -
1:05:26
Man in America
11 hours ago“Poseidon” Doomsday Sub, Microplastics & The War on Testosterone w/ Kim Bright
20.1K18 -
2:23:54
DLDAfterDark
7 hours ago $0.12 earnedGun Talk LIVE! Thursday At The Armory! Feat. Josh of BDG&G & DLD
24K4 -
2:50:16
TimcastIRL
8 hours agoSupreme Court May OVERTURN Gay Marriage, SCOTUS Hearing Set For TOMORROW | Timcast IRL
227K126 -
4:06:47
Barry Cunningham
9 hours agoBREAKING NEWS: PRESIDENT TRUMP HOSTS A STATE DINNER | FOX NATION PATRIOT AWARDS!
107K65 -
4:04:59
Alex Zedra
7 hours agoLIVE! New Game | The See Us
32.4K1 -
1:56:30
ThisIsDeLaCruz
7 hours ago $0.06 earnedOn The Road With Pantera
35.6K3 -
DVR
meleegames
6 hours agoMelee Madness Podcast #58 - They Changed What ‘It’ Was & It’ll Happen to You
24K4 -
2:32:46
megimu32
8 hours agoOn The Subject: Why K-Pop Demon Hunters Feels Like 90s Disney Again
34.5K9