• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Majji's mock exam doubt

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic