Java SE entry-level input and output, javase
In the first article, I introduced the output for the eight basic types. Of course, these outputs are simple. When writing to the stream, I will refine the input and output.
Now, you only need to understand the input and output. The input is actually the input of the keyboard.
public class Hello { public static void main(String[] args ) { int a=20; System.out.println(a); }}
In the appeal Code 20, can I enter it through the console ??? The answer is yes. What are the conditions for the input ???
1. Import the jar package of java. util. keystore. The imported keyword isImport
2. input weight input = new weight (System. in);, where new is an object of the new instance, System. in is enumeration, which will be described later when writing Object-oriented Data. You only need to know this for the time being.
Let's take a look at how keyboard input is accepted.
Corresponding code
Import java. util. extends; public class Hello {public static void main (String [] args) {extends input = new loads (System. in); double d = input. nextDouble (); System. out. println ("the double value you entered =" + d); int I = input. nextInt (); System. out. println ("the int value you entered =" + I); String s = input. next (); System. out. println ("the String value you entered =" + s );}}
Only three types are listed. Other types are the same. We can accept any value input by the keyboard.
Let's enter the side of a square on the keyboard to find the circumference and area of the square.
Enter the circle radius on the keyboard to obtain the circumference and area of the circle.
Import java. util. extends; public class Hello {public static void main (String [] args) {extends input = new loads (System. in); System. out. println ("Enter the side length of the square. Press Enter after the input is complete"); double d = input. nextDouble (); double zhouchang = d * 4; // double mianji = d * d; System. out. println ("square perimeter =" + zhouchang + "Area =" + mianji); System. out. println ("I heard that you also require the circumference and area of the circle, clear and directly enter the radius of the circle"); double r = input. nextDouble (); double Pi = 3.14; zhouchang = 2 * Pi * r; mianji = Pi * r; System. out. println ("circle perimeter =" + zhouchang + "Area =" + mianji );}}