In Java, input depends on the Scanner class . Scanner is a new class added in JDK 1.5. You can use this class to create an object:
Scannerreader=newScanner(System.in);
The reader object calls the following methods to read various basic types of data entered by the user on the command line:
nextBoolean(): input Boolean value
nextByte(): input bytes
nextShort(): input short integer
nextInt(): input integer
nextLong(): input long integer
nextFloat(): input single-precision floating point number
nextDouble(): input double precision floating point number
There are three commonly used output statements in Java:
Line wrap printing will automatically wrap after output.
Print without line breaks.
Output according to the format.
Common format control characters are as follows:
Notice :
When using System.out.println() or System.out.print() to output a string constant, "carriage return" cannot appear, for example:
System.out.println("Hello, nice to meet you");//This way of writing cannot be compiled.
If we need to output a longer string, we can break the string into several parts and then use the concatenation symbol + to connect them end to end, for example:
System.out.println("Hello," + "Nice to meet you");//This is the correct way of writing