scanner user input java code example
Example 1: java scanner
import java.util.Scanner;
Scanner myScanner = new Scanner(System.in);
String inputString = myScanner.nextLine();
boolean inputBoolean = myScanner.nextBoolean();
long inputLong = myScanner.nextLong();
Example 2: scanner in java
import java.util.Scanner;
class classname{
public void methodname(){
Scanner s_name = new Scanner(System.in);
int val1 = s_name.nextInt();
float val2 = s_name.nextFloat();
double val3 = s_name.nextDouble();
string name = s_name.nextLine();
char ch = s_name.nextLine().charAt(0);
}}
Example 3: 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 4: scanner java
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();