take input in java scanner 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: how to use scanners in java
import java.util.Scanner;
Public class Scanner {
Public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Type anything and the scanner will take that input and print it");
String next = scan.next();
System.out.println(next);
}
}
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: how to use scanner class in java
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.println("What is your name?");
String name = input.nextLine();
System.out.println("Hello," + name + " , it is nice to meet you!");