JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 邏輯的問題(or與and)
monkeyc_168





發文: 5
積分: 0
於 2013-07-30 18:48 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
class EBH202 {
    static boolean a, b, c;
    public static void main (String[] args) {
        boolean x = (a = true) || (b = true) && (c = true);
        System.out.print(a + "," + b + "," + c);
    }
}

What is the result of attempting to compile and run the program?

Answer:Prints: true,false,false

以下為講解
The conditional and expression is not evaluated, because the left hand operand of the conditional or expression is true. The original expression is as follows: x = (a = true) || (b = true) && (c = true). The left hand operand of the conditional or expression is the result of the assignment expression, (a = true). Since the left hand operand of the conditional or expression is true, the right hand operand will not be evaluated. In this case, the right hand operand is the conditional and expression. Consequently, neither operand of the conditional and expression is evaluated and the variables, b and c, maintain their default values of false.

看不太懂他的講解
請問有大大能夠解答嗎? 謝謝


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
551 邏輯的問題(or與and) monkeyc_168 1017 2013-07-30 18:48
474 Re:邏輯的問題(or與and) puremonkey2006 320 2013-07-31 11:02
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8