java who to read input code example
Example 1: java get input
Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = sc.nextInt();
double d = sc.nextDouble();
float f = sc.nextFloat();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int c = br.read();
Example 2: read input in java
3 ways to read input from console in java
-----------------------------
1. Using BufferedReader Class
2. Using Scanner Class
3. Using Console Class
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
...
public static void main(String[] args) throws IOException
...
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
import java.util.Scanner;
...
String name = new Scanner(System.in);
String name = Syste.console().readLine();