Operators
Increment and decrement ++ -
++ operations, variables themselves up 1. On the contrary - operations, variables reduce their own 1.
Independent operation: independent variables in the operation, and the front ++ ++ no difference. That is, ++, - when used alone in the front and rear variable is no different. Or +1 is decremented.
Arithmetic expression: +, - the expression operators in front of variable ++ ++ and calculated variables is different. ++, -, if the operation time in the expression before and after the variable is different. ++, - if after the variable, the first value computation using a variable, then the variables are incremented or decremented. ++, - if in front of the variable, the variables are first increment or decrement, and then involved in computing
And the difference & && (&& The first is the false second is not executed, & two will be handled) (but as the results of even a)
| of the difference between || (| if the first condition is true, the second result will still judge, will judge || first) (two execution result is the same)
(developed by && ||! the reason is more efficient and does not judge the second condition)
Ternary operator
data type variable name = boolean expression? Results 1: 2 results;
A data input (Scanner)
Steps for usage
We can get the user's input through the Scanner class. Use the following steps:
1, the leader packet. Scanner class in java.util package, it is necessary to import the class. Guide package statement requires the class defined above.
import java.util.Scanner;
2, the object is created Scanner
Scanner sc = new Scanner(System.in);//创建Scanner对象,sc表示变量名,其他均不可变
3, the received data
int i = sc.nextInt();//表示将键盘录入的值作为int数返回。
example:
import java.util.Scanner;
public class ScannerDemo{
public static void main(String[] args){
//创建对象
Scanner sc = new Scanner(System.in);
//接受数据
int x = sc.nextInt();
//输出数据
System.out.println("x:" + x);
}
}