Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2007, 05:48 PM
Member
 
Join Date: Jul 2007
Posts: 4
ritwik07 is on a distinguished road
Boolean Expression
Quote:
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2007, 06:01 PM
Member
 
Join Date: Jul 2007
Posts: 51
mary is on a distinguished road
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
Code:
int i=0; int j=10; If(i==j){System.out.println(1);}else {System.out.println(0);}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-11-2007, 04:46 AM
Member
 
Join Date: Jul 2007
Posts: 4
ritwik07 is on a distinguished road
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
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
Code:
(i==j)
is a pure integer expression. Why does'nt it give an intger value???
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-11-2007, 05:11 AM
Member
 
Join Date: Jul 2007
Posts: 44
simon is on a distinguished road
i==j is a boolean expression, mary is right
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression for unicode tharhan Advanced Java 0 04-01-2008 11:53 PM
boolean to string otoro_java New To Java 2 01-30-2008 06:31 AM
Regular expression with Unions Java Tip Java Tips 0 01-09-2008 01:03 PM
boolean variables ravian New To Java 3 12-31-2007 05:58 AM
Error: incompatible types, found: int required: boolean silvia New To Java 1 07-19-2007 08:33 PM


All times are GMT +3. The time now is 11:32 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org