Scanner Object In Java Code Example

Snippet 1
  //Import Scanner in java
import java.util.Scanner;

class classname{
  public methodname(){
    //Scanner declaration
    Scanner s_name = new Scanner(System.in);
    //Use Scanner to take input
    int val = s_name.nextInt();
  }
} 
Snippet 2
  import java.util.Scanner;

// import scanner 

Scanner myScanner = new Scanner(System.in); // Make scanner obj

String inputString = myScanner.nextLine(); // Take whole line

boolean inputBoolean = myScanner.nextBoolean(); //Boolean input

long inputLong = myScanner.nextLong(); //Interger,long ... input 
Snippet 3
  import java.util.Scanner;