1. Scanner class
the console scan class provided by the JDK is used to read information from the console input. Import Java.util.Scanner required before use; (Import Package).
Use:
Created object: Scanner SCA = new Scanner (system.in);
Get string: String str1 = Sca.next (); The end can be indicated by a space, carriage return line character (\ r \ n)
String str2 = Sca.nextline (); can only end with \ r \ n
Get integer: int num = Sca.nextint ();
Get decimal: Double d = sca.nextdouble ();
Case 8:
650) this.width=650; "style=" width:661px;height:413px; "title=" 8b3q%p85f) 2s3.png "src=" http://s3.51cto.com/wyfs02/ M01/6c/c1/wkiom1vrdtdtt5z0aajpobtw1t4630.jpg "width=" 721 "height=" 457 "alt=" wkiom1vrdtdtt5z0aajpobtw1t4630.jpg "/ >
Case 9:
650) this.width=650; "style=" width:660px;height:405px; "title=" 9e.png "src=" http://s3.51cto.com/wyfs02/M0 1/6c/bc/wkiol1vrduedrac2aakhtqks-wc236.jpg "width=" 740 "height=" 437 "alt=" wkiol1vrduedrac2aakhtqks-wc236.jpg "/ >
Output Result:
650) this.width=650; "title=" 999aj4qy9_@) drf.png "src=" http://s3.51cto.com/wyfs02/M01/6C/C1/wKiom1VRdY2y Zo56aacudvi8n2q231.jpg "alt=" Wkiom1vrdy2yzo56aacudvi8n2q231.jpg "/>
2. Random class
The JDK provides a class that obtains random numbers, which are used to obtain random decimals, integers, Boolean types, and so on. Import java.util.Random required before use;
Use:
Create object: Random random = new random ();
/ /Get a random integer in the range: int num = Ran.nextint (n);//value [0, N)
Gets the random Boolean value: Boolean flag = Ran.nextboolean ();
Get random decimals: double d = ran.nextdouble ();
Case Study:
650) this.width=650; "title=" 10.png "src=" Http://s3.51cto.com/wyfs02/M02/6C/C1/wKiom1VRdevSgt-JAAHX9Pliv Oi537.jpg "alt=" Wkiom1vrdevsgt-jaahx9plivoi537.jpg "/>
This article is from "Forever Young" blog, please be sure to keep this source http://kingkongzhao.blog.51cto.com/6319491/1650551
Java Basic Learning Notes--6 (Scanner, Random)