Scanner int 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: 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 4: scanner java
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
Example 5: read int from keyboard java
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scan= new Scanner(System.in);
String text= scan.nextLine();
System.out.println(text);
int num= scan.nextInt();
System.out.println(num);
}
}
Example 6: how to create a Scanner Object in java
Scanner console = new Scanner(System.in);