In the first, eight basic types of time, I introduced the output, of course, these outputs are simple, subsequent writes to the stream when the input output is refined.
It is now only required to understand the input and output. The input is actually accepting the keyboard input.
Public class Hello { publicstaticvoid main (string[] args) { int a=; System. out . println (a); }}
20 in the appeal code, can I enter it through the console??? The answer is yes, what are the criteria for the input???
1 Import java.util.Scanner jar package, import keyword called import
2. In the program weight input Scanner input =new Scanner (system.in);, where new is an object, and System.in is an enumeration, these follow-up writes object-oriented time will say, temporarily as long as you know how to write it.
Let's take a look at how to accept keyboard input.
corresponding Code
import Java.util.Scanner; Public classHello { Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); DoubleD=input.nextdouble (); System. out. println ("The Double value you entered ="+d); intI=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 equivalent. We can accept any value entered by the keyboard.
We let the keyboard enter a square edge to find the circumference and area of the square.
Write a keyboard input circle radius to find the circumference and area of the circle.
import Java.util.Scanner; Public classHello { Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); System. out. println ("Please enter the side length of the square and press ENTER when finished"); DoubleD=input.nextdouble (); DoubleZhouchang =d*4;// Doublemianji=d*D; System. out. println ("the circumference of a square ="+zhouchang+"area ="+Mianji); System. out. println ("I heard that you also require the circumference and area of the circle, clear the radius of the direct input Circle"); DoubleR=input.nextdouble (); DoublePi=3.14; Zhouchang=2*pi*R; Mianji=pi*r*R; System. out. println ("circumference of the circle ="+zhouchang+"area ="+Mianji); }}
Input and output of Java SE entry