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:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# BItwise & logical operators question

Greenhorn
Posts: 18
• • Number of slices to send:
Optional 'thank-you' note:
• • Which statements @ the O/P of the foll. are true?
public class Logic
{
public static void main(String args[])
{
int i = 0;
int j = 0;

boolean t = true;
boolean r;
r = (t & 0<(i+=1));
r = (t && 0<(i+=2));
r = (t | 0<(j+=1));
r = (t | | 0<(j+=2));

System.out.println(i+""+j);
}//main
}//class
1. 1st digit printed is 1
2. 1st digit printed is 2
3. 1st digit printed is 3
4. 2nd digit printed is 1
5. 2nd digit printed is 2
6. 2nd digit printed is 3

Ranch Hand
Posts: 5040
• • Number of slices to send:
Optional 'thank-you' note:
• • Chamya:
Please let us know what you think should be the ans.
Regds. - satya

Ranch Hand
Posts: 396
• • Number of slices to send:
Optional 'thank-you' note:
• • hi chamya,
the statement 3 and 4 are true.
remember && and | | are short circuit operators.so they may not evaluate the operand on RHS if the result can be deduced by calculating LHS opearand only.
regards
deekasha

Chamya Pehalvan
Greenhorn
Posts: 18
• • Number of slices to send:
Optional 'thank-you' note:
• • I do not know the answere to the given code & hence my question to whoever can help me solve it!

Originally posted by Chamya Pehalvan:
Which statements @ the O/P of the foll. are true?
public class Logic
{
public static void main(String args[])
{
int i = 0;
int j = 0;

boolean t = true;
boolean r;
r = (t & 0<(i+=1));
r = (t && 0<(i+=2));
r = (t | 0<(j+=1));
r = (t | | 0<(j+=2));

System.out.println(i+""+j);
}//main
}//class
1. 1st digit printed is 1
2. 1st digit printed is 2
3. 1st digit printed is 3
4. 2nd digit printed is 1
5. 2nd digit printed is 2
6. 2nd digit printed is 3

Sheriff Posts: 3341
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by Chamya Pehalvan:
I do not know the answere to the given code & hence my question to whoever can help me solve it!

Pen and paper

the answers are 3 and 4 