Java Tutorial: Getting User Input in Java
Reading data from the Keyboard :
- Scanner class of java.util package is used to take input from the user's keyboard.The Scanner class has many methods for taking input from the user depending upon the type of input. To use any of the methods of the Scanner class, first, we need to create an object of the Scanner class as shown in the below example :
Taking an integer input from the keyboard :
Code:
Chapter 1 – Practice Set
- Write a program to sum three numbers in Java.
- Write a program to calculate CGPA using marks of three subjects (out of 100)
- Write a Java program that asks the user to enter his/her name and greets them with “Hello <name>, have a good day” text.
- Write a Java program to convert Kilometers to miles.
- Write a Java program to detect whether a number entered by the user is an integer or not.
Handwritten Notes: Click To Download
Ultimate Java Cheatsheet: Click To Download