SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Java

  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2001
    Location
    earth
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello.

    Could anyone explain me the result of this:

    Show the result of the following Boolean expressions if the result can be determined.

    (true) && (3 > 4)
    !(x > 0) && (x > 0)
    (x > 0) || (x < 0)
    (x != 0) || (x == 0)
    (x >= 0)||(x < 0)
    (x != 1) ==!(x = 1)



    Thank you.

  2. #2
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is x? That can make a difference for the results. Let's assume x is 1. Why not have JavaScript do the work for you...

    <script language="JavaScript">
    <!--
    var x = 1
    document.write ("x = " + x + "<br>");
    document.write ("(true) && (3 > 4) " + ((true) && (3 > 4)) + "<br>" );
    document.write ("!(x > 0) && (x > 0) " + (!(x > 0) && (x > 0)) + "<br>" );
    document.write ("(x > 0) || (x < 0) " + ((x > 0) || (x < 0)) + "<br>" );
    document.write ("(x != 0) || (x == 0) " + ((x != 0) || (x == 0)) + "<br>" );
    document.write ("(x >= 0)||(x < 0) " + ((x >= 0) || (x < 0)) + "<br>" ) ;
    document.write ("(x != 1) ==!(x = 1) " + ((x != 1) ==!(x = 1)) + "<br>" );
    // -->
    </script>

    If you don't understand what all of the symbols are ( ||, &&, ==), they're comparison operators.

    != Test for inequality
    == Test for equality
    && Logical AND
    || Logical OR

  3. #3
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So with x being 1, the following results are shown...

    (true) && (3 > 4) false
    !(x > 0) && (x > 0) false
    (x > 0) || (x < 0) true
    (x != 0) || (x == 0) true
    (x >= 0)||(x < 0) true
    (x != 1) ==!(x = 1) true

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2001
    Location
    earth
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello.

    I've to say that this is for my sister. She is learning Java on University.

    The teacher give her this exercise. She asks me but me and Java, unhappyly, we have (until now) a distant relationship.

    Thank you. I'll show my sister your answer.

    magi::::::::::::::

  5. #5
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And just for the record, remember that Java and JavaScript are not the same thing. The example I have above uses JavaScript. You can do the comparisons in Java too, but the syntax is different.


Bookmarks

Posting Permissions

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