Results 1 to 4 of 4

Thread: true && !true

  1. #1
    SirFalcon is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default true && !true

    Can someone explain to me what true && !true does?

    Here is a sample code:

    Java Code:
    		int a,b,c,d;
    		a = 10;   b = 4;   c = 2;   d = 3;
    		if ((c + 2 < d) || ((c * d) == (a - b))) 
    				if (true || (true && !true)) 
    					System.out.print("X");
    				else {
    					System.out.print("Y");
    					System.out.print("Z");
    				}
    I know that the nested if is executed since ((c * d) == (a - b)) = TRUE. However, if I change the nested IF to if (true && !true) instead, I don't get why Y and Z is printed. Doesn't it mean TRUE or NOT TRUE and thus X would always be printed?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    1) what is !true? In other words, what is (not) true?

    2) what is anything && the answer to question 1) above

    3) regardless of this answer, what is (true || anything)?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    if (true && !true) instead, I don't get why Y and Z is printed. Doesn't it mean TRUE or NOT TRUE
    Nope. You'd better look up what is used for AND and what is used for OR in Java. This is a basic concept that you'll need as you go forward.

  4. #4
    SirFalcon is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

Similar Threads

  1. while(true)
    By ravian in forum New To Java
    Replies: 7
    Last Post: 06-29-2011, 07:05 AM
  2. which one of the following is true about interface?
    By makpandian in forum New To Java
    Replies: 3
    Last Post: 06-30-2009, 01:23 AM
  3. A true newbies problem.
    By Kaz in forum New To Java
    Replies: 3
    Last Post: 06-25-2009, 07:12 AM
  4. bug (?) in ProcessBuilder.redirectErrorStream(true);
    By gadasie in forum Advanced Java
    Replies: 3
    Last Post: 03-13-2008, 10:04 AM
  5. setVisible(true) does not work
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 2
    Last Post: 10-27-2007, 08:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •