1 classdemo02{2 Public Static voidMain (string[] args) {3 //arithmetic operator +,-, *,/,%,++,--4 5 //Example 16 intA = 1;7 intb = 2;8 intc = 3;9System.out.println (a+b+c);Ten //Results 6 One /* A a+b+c the execution process - 1: Go to the memory to find a corresponding data - 2: Read the next operator the 3: Read the operand B after a, colleague Yaodu District B after the operator, to see whether to run first. - 4: Calculate the results of the a+b - 5: Add the result of A+b and C - */ + - + //Example 2 A intA = 1; at intb = 2; - intc = 3; - intD = 4; -System.out.println (a+b+c*d); - //Results - /* in Execution Process - 1: Calculate the value of the a+b first to 2: Calculation c*d + 3: Add the value of A+b and the value of C*d - */ the * $ //Example 3Panax Notoginseng intA = 1; - intb = 2; theSystem.out.println ((a=3) + (b=4) +a*b); + //Results A the + //Example 4 - //Interview question: Please design an expression to determine whether a data is an odd number $ //System.out.println (5%2); $ //System.out.println (5%-2); - //System.out.println ( -5%2); - //System.out.println ( -5%-2); the //result 1,1,-1,-1 - //Conclusion:% is the symbol that provides the result of the operation by the preceding operandWuyi return(i%2!=0) the - Wu //Example 5 - //+ +,--operator About //int i = 1; $ //i++; is an expression where the value of the equation is the same as the value of I - //++i; is an expression, the value of which is the value after i+1 - //+ +,--must be a variable - intI=1; ASystem.out.println (i+++i+++i+++i++); + //Results Ten the //i++ + i++ + i++ + i++ - //1 + i++ + i++ + i++ i=2 $ //1 + 2 + i++ + i++ i=3 the //1 + 2 + 3 + i++ i=4 the //1 + 2 + 3 + 4 i=5 the the - //Example 6 in intI=1; theSystem.out.println (i++ + ++i + i++ + + +)i); the //Results About //If you write System.out.println (i+++++i+i+++++i), the compiler will error the } the}
Java interview (2)--Java arithmetic expression