一、求余符号:%
1. public class Student{
2. public static void main(String[] args){
3. int i1 = 12 % 5;
4. int i2 = -12 % 5;
5. int i3 = 12 % (-5);
6. int i4 = -12 % (-5);
7. System.ou.println("以此输出i1,i2,i3,i4");
8. }
9. }
运行后可得答案 2,-2, 2 ,-2。
由此可得,求余运算符最终结果的符号,由被余数。
二、‘++’运算符
1. public class Student{
2. public static void main(String[] args){
3. int myInt1 = 10;
4. int myInt2 = myInt1++;//后++
5. System.out.println(myInt1);// 结果为 11
6. System.out.println(myInt2);// 结果为 107. //**********************
9. int myInt3 = 10;
10. int myInt4 = ++myInt3;//前++
11. System.out.println(myInt3); // 结果为 11
12. System.out.println(myInt4); // 结果为 11
13. }
14. }
可以看出,‘++’放在变量前后有不同的效果。