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().
-
1:42:41
Glenn Greenwald
6 hours agoReaction to Trump's Primetime Speech; Coldplay "Adultery" Couple Reappears for More Shame; Australia and the UK Obey Israel's Censorship Demands | SYSTEM UPDATE #560
95.1K49 -
2:46:41
Barry Cunningham
4 hours agoBREAKING NEWS: President Trump Signs The National Defense Authorization Act | More News!
17.4K16 -
43:10
Donald Trump Jr.
5 hours agoThe Days of Destructive DEI are Over, Plus Full News Coverage! | TRIGGERED Ep.301
89.8K60 -
52:07
BonginoReport
5 hours agoThe Internet Picks Bongino’s FBI Replacement - Nightly Scroll w/ Hayley Caronia (Ep.200)
81.3K56 -
55:30
Russell Brand
6 hours agoStay Free LIVE from AmFest — Turning Point USA - SF665
116K14 -
1:11:26
Kim Iversen
7 hours agoTrump Pulls War Fake-Out…Attack on Venezuela Still Coming!?
75.7K98 -
2:04:53
Redacted News
6 hours agoPutin just changed EVERYTHING with this move and NATO can't do anything | Redacted w Clayton Morris
168K132 -
25:22
DeVory Darkins
6 hours agoTrump scores MAJOR WIN after Inflation Report as his speech sparks EPIC MELTDOWN
53.2K55 -
1:01:23
Nick Freitas
7 hours agoLIVE at America Fest!
68.5K3 -
1:11:19
vivafrei
8 hours agoCandace Owens' Backtracks? Brown University Cover-Up? Bongino Leaves! Pfizer Makes LEGAL ADMISSIONS?
148K78