1. true and false
1.1 if--else if--else, while, do--while all use the truth or falsehood of the conditional expression to determine the execution path.
1.2 Java does not allow numbers to be used as true or false judgments, C and C++ can be either 0 or true.
2.Math.random()
- Yields a double value [ 0, 1 ) including 0 and excluding 1.
3.foreach syntax
- For example, for(float x: f){ } f is an array, any method that returns an array can use foreach
4.return
- return causes the current method to exit, returning the value.
- Except for the constructor, any method has a return value type such as void fun(), String fun(), void fun(), no need to write return, there is return by default, other methods must have a return value (or an expression produces a value )
5.break和continue
- break terminates the current layer loop and exits the loop, continue terminates the current layer loop and enters the next loop.
5.1 Label: Use when you want to jump out of nested loops
continue leaf;//Jump to the loop where the label is located to start recirculating, note that i will not increase in the inner loop, // break leaf; jump out of the loop where the label is located, no longer loop, and inner i will not increase
bed: // No other code can be added between the label and the iterator for (j = 0; j < 5; j++) { System.out.println("外"); for (; i < 10; i++) { if (i == 6) { continue leab; // break leab; } System.out.println("nei"); } }
6. switch(value)
switch(i){ // case 1: System.out.println(1);break; case 2: System.out.println(1); case 'a': System.out.println(97);break; // char 'a' is automatically converted to ASCII }