Table of Contents

nextInt()

public int nextInt()

return int scanned from the input

example nextInt in java

package scanner;
 
import java.util.Scanner;
 
public class Scanner {
 
    public static void main(String[] args) {
 
        /* Create Scanner Object for the input from the keyboard */
        Scanner scan = new Scanner(System.in); 
 
        int currency;
 
        System.out.print("Please enter a number: ");
        currency = scan.nextInt(); // read currency
 
        System.out.println("Number is " + currency);
 
        scan.close(); // close the object 
    }
}

output of nextInt()

  Please enter a number: 42
  Number is 42