(a) Learning summary
1. In Java, through the scanner class to complete console input, consult the JDK Help document, scanner class implementation of basic data input method? Can not only use text description, must write code, through specific examples to explain.
Text Scan class Scanner (Java.util.Scanner), you can use different next methods to enter text into different types of values. The way to get basic type data is:
NEXTLNT (): reads integer data.
Nextdouble (): reads double-precision data.
Next (): reads the next word in the input (space is the delimiter)
Nextline (): reads the next line of input
Constructs a scanner object and associates with system.in
Scanner input=next Scanner (system.in);
Various methods of invoking scanner to complete the input operation
Int Num=input.nextint ();
Cases:
The random () method of the 2.Random class and the math class can produce a stochastic number, what is the difference between these two ways, and what are the characteristics of each? Consult the JDK Help documentation for an example.
I. Random class generation of stochastic
Grammar random ran=new random ();
An instance object of the Ran:random class. When you instantiate an object, the Java compiler takes the seed from the system at that time as a random number generator, because the random number that is generated at different times of the hour is different.
Two. The random () method of the Math class
The random () method of the math class can generate a double type of number greater than 0.0, less than 1.1, which can obtain random numbers of multiple types, or arbitrary ranges.
public static void Main (string[] args) {
int x= (int) (Math.random () *100);
Random rand=new random ();
int Y=rand.nextint (3);
System.out.println (a);
System.out.println (b);
}
3. What is the result of running the following procedure? Check the information and analyze why.
The result is not equal to 0.3
In order to deal with the loss of precision, you can use the Java.math.BigDecimal class, consult the JDK help document or the textbook p378 to modify the above procedure.
Knowledge Points: Numbers that do not require any accurate calculation accuracy can be directly used with a float or double, but you must use the BigDecimal class if you need to calculate the exact result.
Cause of error: in the process of adding and subtraction, a floating-point error is generated, and cannot be used to represent the result of floating-point type data.
Correction Method:
Using the round method to determine the accuracy range, you need to use Mathcontext.
4. The main points of this study other needs to summarize the content: individual, according to their own learning situation, record difficult to grasp or difficult to understand the content, as well as learn the content of the experience. There are still problems, you can also put forward, for students in the blog raised questions, we can actively discuss, peer education.
Learning Java needs to have a solid C language Foundation, for C linguistics is not good for me, have to work hard.
Write the procedure to have clear is the road, the idea is clear and then write.
II) Experimental Summary
1. Guess the price of the commodity
(1) Randomly generated price
(2) Enter the price you guessed
(3) Use a Loop 1. The opportunity has 10 times, if the opportunity runs out, the output price
2. Lower than the real price: the output guessed low, higher than the real price: the output guessed high, if the guessed right, then output the real price.
3. Mutual assessment Results
1. Designing array-valued functions
2. In the averaging function, call the value function, sum each element and subtract the maximum value for averaging
3. Call the sort function order, output the score
Note: When outputting tabs, double quotation marks should be used
Java first time job