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:16
DeVory Darkins
17 hours ago $4.05 earnedMedia Panics after Trump Threatens to Sue Media for Defamation
14K53 -
2:15:34
Matt Kohrs
4 hours agoFed Powell Speech & FOMC Rate Decision
9.91K2 -
LIVE
StoneMountain64
3 hours agoThe MOST hyped game of the YEAR
230 watching -
1:50:12
The Quartering
18 hours agoTim Pool SELLS TO DAILY WIRE? Never Eat Hot Dogs Again, Drones & More
74.3K19 -
1:17:48
Tucker Carlson
4 hours agoTom Homan’s Plan to Destroy the Cartel Empire, End Child Trafficking, and Secure the Border for Good
113K133 -
1:06:28
Russell Brand
6 hours agoWho Ordered the Hit on Russia’s General Krylov? - SF516
131K243 -
54:50
The Kevin Trudeau Show
5 hours agoWhat Men Do Wrong In Relationships | Ep. 75
11.9K3 -
12:41
Gun Owners Of America
4 hours agoWe're Fighting Back Against Mexico In Court!
19K4 -
2:57:11
The Charlie Kirk Show
4 hours agoThe CR Quagmire + An Hour of PBD + Catholic in Hollywood | Davis, Patrick Bet David, Rep. Burlison
119K32 -
32:54
Kicking Mustang
9 hours ago $1.95 earnedWatch the Best Ghillie Sniper Moments of 2024...
20.3K3