Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to enter an integer value in Java and assign it to a variable?
How to enter an integer value in Java and assign it to a variable?
JAVA uses streams to receive input, or it can input directly.

Common class T{

Public static void main (string [] args)//string [] args This is to receive parameters.

int a = 0;

if(args.length()! = 1){

//This is to decide whether to enter only one parameter.

If you don't print the prompt yourself, you are logging out of the system.

Otherwise {

//parameters of receiving parameters

//It is also necessary to judge whether the input is a numerical value. Just use the following sentence after the judgment is completed. This is to get the input value directly, and no stream is needed. If streams are used

a=Integer.parseInt(args。 [0])}

}

The following is the usage stream scanner in = new scanner (system. in);

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

int a;

a = in . nextint();