Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to input numbers from keyboard with JAVA? What keywords are used?
How to input numbers from keyboard with JAVA? What keywords are used?
Scanner sc = new scanner (system. in);

int j = sc . nextint();

If the nextInt () method is used, the next mark in the input information of this scanner can be Interpreted as the int value in the default radix.

Keywords: general scanner.

Extended data

Read integer or floating-point data from the keyboard with a scanner;

Import? Java . util . *;

Common class test {

Public static void main(String args[])

{

Scanner in = new scanner (system. in); //Define an object using the Scanner class

System.out.println ("Please enter a floating-point number");

float a = in . next float(); //receive floating-point data

system . out . println(a);

System.out.println ("Please enter an integer");

int b = in . nextint(); //receive shaping data

system . out . println(b);

}

}