标签:ar sp div 代码 bs ad amp as nbsp
算术运算符及代码:
public class Test{
public static void main(String []args){
int i1 = 10;
int i2 = 20;
int i = 0;
i = i1++;
System.out.print("i = " + i);
System.out.println(" i1 = " + i1);
i = ++i1;
System.out.print("i = " + i);
System.out.println(" i2 = " + i2);
i = i2--;
System.out.print("i = " + i);
System.out.println(" i2 = " + i2);
i = --i2;
System.out.print("i = " + i);
System.out.println(" i2 = " + i2);
}
} i = i1 ++,先将i1赋给i,再将i1加1,既(i = i1;i1 = i1 + 1;) 。 i = ++ i1,先将i1加1,再将i1的值赋给i,既(i1 = i1 + 1;i = i1;) 。 i --,--i同理
逻辑运算符及代码:
! 逻辑非 & 逻辑与 | 逻辑或 ^ 逻辑异或 && 短路与 || 短路或 public class Test1 {
public static void main (String []args) {
boolean a,b,c;
a = true;
b = false;
c = a & b; System.out.println(c);
c = a | b; System.out.println(c);
c = a ^ b; System.out.println(c);
c = ! a;System.out.println(c);
c = a && b; System.out.println(c);
c = a || b;System.out.println(c);
}
}
赋值运算符及代码:
= ,+=,-=,*=,/=,%,/
= 赋值运算符
+= 先加再赋值
-= 先减再赋值
/=先取整再赋值
%先取余再赋值
三目运算符:X ? Y :Z
如: grade>60?"及格":“不及格”(成绩大于60则及格,否则不及格)
运算符及代码
标签:ar sp div 代码 bs ad amp as nbsp
原文地址:http://www.cnblogs.com/dingxiaoblog/p/4082542.html