- Reading data from the Keyboard
In order to read data from the keyboard, Java has a scanner class.
Scanner class has a lot of methods to read the data from the keyboard.
Scanner S = new Scanner(System.in); //(Read from the keyboard)
int a = S.nextInt(); //(Method to read from the keyboard)
package com.company;
import java.util.Scanner;
public class CWH_05_TakingInpu {
public static void main(String[] args) {
System.out.println("Taking Input From the User");
Scanner sc = new Scanner(System.in);
// System.out.println("Enter number 1");
// int a = sc.nextInt();
// float a = sc.nextFloat();
// System.out.println("Enter number 2");
// int b = sc.nextInt();
// float b = sc.nextFloat();
// int sum = a +b;
// float sum = a +b;
// System.out.println("The sum of these numbers is");
// System.out.println(sum);
// boolean b1 = sc.hasNextInt();
// System.out.println(b1);
// String str = sc.next();
String str = sc.nextLine();
System.out.println(str);
}
}