Check out example codes for "scanner in java". It will help you in understanding the concepts better.

Code Example 1

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

class classname{
  public methodname(){
    //Scanner declaration
    Scanner s_name = new Scanner(;
    //Use Scanner to take input
    int val = s_name.nextInt();

Code Example 2

import java.util.Scanner;

Public class Scanner {
	Public static void main(String[] args) {
    	// Scanner *scanner name here* = new Scanner(;
      	Scanner scan = new Scanner(;
      	System.out.println("Type anything and the scanner will take that input and print it");
      	String next =;

Code Example 3

import java.util.Scanner;

// import scanner 

Scanner myScanner = new Scanner(; // Make scanner obj

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

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

long inputLong = myScanner.nextLong(); //Interger,long ... input

Code Example 4

import java.util.Scanner;

Code Example 5

import java.util.Scanner;//import Scanner

Scanner input=new Scanner(;//Create the scanner Obj

float numF = input.nextFloat();//Returns float
int num1 = input.nextInt(); //Returns int
byte byte1 = input.nextByte();//Returns Byte
long lg1 = input.nextLong();//Returns long
boolean b1 = input.nextBoolean();//Returns bool
double num2 = input.nextDouble();//Returns Double
String nome = input.nextLine();//Returns String

//execution is pause until you give input

Code Example 6

import java.util.Scanner;
  Scanner console = new Scanner(;
  int num = console.nextInt();
  console.nextLine() // to take in the enter after the nextInt() 
  String str = console.nextLine();

Learn ReactJs, React Native from