How to enter a text or number from keyboard without using InputStreamReader method in java?
Java Input values using Scanner Class
You can use Scanner class to input text or integer or double value. This class is having several different method to input string value, integer value, double value, float value etc.
import java.util.*; class InputUsingScannerClass { public static void main(String[]args){ Scanner input=new Scanner(System.in); System.out.println("Enter string:"); String str=input.nextLine(); System.out.println("Enter integer:"); int num1=input.nextInt(); System.out.println("Enter double value:"); double num2=input.nextDouble(); System.out.println("Enter long value:"); long num3=input.nextLong(); System.out.println(); System.out.println("Input Values: "); System.out.println(str); System.out.println(num1); System.out.println(num2); System.out.println(num3); } }
Ads