1 public class RelationAndConditionOp{
2 public static void main( String args[] ){
3 int a=25,b=3;
4 boolean d=a<b; //d=false
5 System.out.println("a<b = "+d);
6
7 int e=3;
8 if(e!=0 && a/e>5)
9 System.out.println("a/e = "+a/e);
10 int f=0;
11 if(f!=0 && a/f>5)
12 System.out.println("a/f = "+a/f);
13 else
14 System.out.println("f = "+f);
15 }
16 }
17 其运行结果为:
18 C:\>java RelationAndConditionOp
19 a<b = false
20 a/e = 8
21 f = 0
22 //注 意 :上 例 中 ,第 二 个 if语 句 在 运 行 时 不 会 发 生 除 0溢 出的错 误 ,因 为 e!=0为false,所 以 就 不 需 要 对 a/e进 行 运 算 。