if(radius >=0){
area = radius * radius * PI;
System.out.println("The area for the circle of radius "+ radius +" is "+ area);}if(radius >=0){
area = radius * radius *3.14159;
System.out.println("The area for the circle of radius "+ radius +" is "+ area);}else{ System.out.println("Negative input");}if(score >90.0)
grade = ‘A’;elseif(score >=80.0)
grade = ‘B’;elseif(scroe >=70.0)
grade = ‘C’;elseif(score >=60.0)
grade = ‘D’;else
grade = ‘F’
// 高手的ifif(number %2==0)
even =true;else
even =false;//新手
等价于
even =(number %2==0);//高手if(even ==true)
System.out.println(“It is even.”);
等价于
if(even)
System.out.println(“It is even.”);
括号优先级最高,如果括号有嵌套,内部括号优先执行。
如果没有括号,则根据操作符的优先级和结合规则确定执行顺序。
如果相邻的操作符有相同的优先级,则根据结合规则确定执行顺序。
除赋值运算符之外的二元运算符都是左结合的。
赋值运算符和?:运算符是右结合的。
例如:
a+b-c+d 等价于 ((a+b)-c)+d
a=b+=c=5 等价于 a=(b+=(c=5))
操作符的优先级和结合规则只规定了操作符的执行顺序。操作数从左至右进行运算。
二元操作符左边的操作数比右边的操作数优先运算。例如:
int a =0;int x = a +(++a);
x的结果为1int a =0;int x =(++a)+ a;
x的结果为2