File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Majji's mock exam doubt

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Hi,

How the following code is giving true as output...

int i=10;
int j=10;
boolean b=false;
if(b=i==j)
System.out.println("true");
else
System.out.println("false");

as conditional operators have higer precedence i==j will be evaluated and returns true ,but b is defined as false,so
if(b=....) returns false ..please can anybody help me..thanks in advance
regds
krishna
 
Savithri Devaraj
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by krishna:
Hi,

How the following code is giving true as output...

int i=10;
int j=10;
boolean b=false;
if(b=i==j)
System.out.println("true");
else
System.out.println("false");

as conditional operators have higer precedence i==j will be evaluated and returns true ,but b is defined as false,so
if(b=....) returns false ..please can anybody help me..thanks in advance
regds
krishna

since i==j returns true, that is assigned to b. Assignment b=true returns true,and hence the answer
Savithri
[This message has been edited by Savithri Devaraj (edited August 17, 2000).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic