Java Home

龙的天下

 

关系运算符和布尔逻辑运算符的使用

 

 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/= 8 
21 = 0 
22 //注 意 :上 例 中 ,第 二 个 if语 句 在 运 行 时 不 会 发 生 除 0溢 出的错 误 ,因 为 e!=0为false,所 以 就 不 需 要 对 a/e进 行 运 算 。

posted on 2009-03-28 11:35 杨帆 阅读(415) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(2)

随笔档案

文章档案

新闻档案

链接(点击进入以下空间):

搜索

最新评论

阅读排行榜

评论排行榜