- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to read numbers from users
The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.
- 1. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
- 2. A scanning operation may block waiting for input.
- 3. A Scanner is not safe for multi-threaded use without external synchronization.
The nextInt() method of the Scanner class is used to read an integer value from the source.
Example
import java.util.Scanner; public class ReadingNumbersFromUser { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter a number ::"); int num = sc.nextInt(); System.out.println("Number entered is :: "+num); } }
Output
Enter a number :: 5564 Number entered is :: 5564
- Related Articles
- Haskell program to read numbers from standard input
- Java Program to Read The Number From Standard Input
- Python program to read input from console
- Java Program to read map by Map.Entry
- Java Program to read the next byte of data from the input stream
- Golang program to create an integer array that takes inputs from users.
- Golang Program to create a string array that takes inputs from users.
- Ways to read input from console in Java
- Java Program to Display All Prime Numbers from 1 to N
- Read integers from console in Java
- Kotlin Program to Read The Number From Standard Input
- How to read data from .csv file in Java?
- Python Program to Read Two Numbers and Print Their Quotient and Remainder
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Haskell Program to read an integer number from the user

Advertisements