Results 1 to 4 of 4
  1. #1
    ritwik07 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Question Boolean Expression

    class Ritz
    {
    public static void main(String args[])
    {
    int i=0;
    int j=10;
    System.out.println(i==j);
    System.out.println(i!=j);
    }
    }
    Why does this fragment result in 'false' and 'true'?
    Why doesnt it display 0 and 1 as its a pure integer expression?

  2. #2
    mary is offline Member
    Join Date
    Jul 2007
    Posts
    51
    Rep Power
    0

    Default

    Because you are printing the result of comparing i with j, and the result will be boolean
    If you want that it prints 1 or 0 you have to write it
    Java Code:
    int i=0;
    int j=10;
    If(i==j){System.out.println(1);}else {System.out.println(0);}

  3. #3
    ritwik07 is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Unhappy

    Quote Originally Posted by mary View Post
    Because you are printing the result of comparing i with j, and the result will be boolean
    If you want that it prints 1 or 0 you have to write it
    Java Code:
    int i=0;
    int j=10;
    If(i==j){System.out.println(1);}else {System.out.println(0);}
    I know th use of 'if'. But the question is that
    Java Code:
    (i==j)
    is a pure integer expression. Why does'nt it give an intger value???

  4. #4
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2008, 08:09 AM
  2. regular expression for unicode
    By tharhan in forum Advanced Java
    Replies: 0
    Last Post: 04-01-2008, 10:53 PM
  3. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 05:31 AM
  4. Regular expression with Unions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 12:03 PM
  5. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 04:58 AM

Posting Permissions

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