• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question from javacross.com

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
anyone tell me the solution for this question found at www.javacross.com
State the output of the following code�
public class short{
��������� public static void main(String args()){
��������� int t=0;
��������� boolean t=true;
��������� boolean f=false,b;
��������� b=(t | | ((i++) ==0));�
��������� b=(f | | ((i+=2)>0));�
��������� System.out.println(i);�
�������� }
}�

also please suggest me some good books available.
thankyou.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there are 4 errors in the code
1) the class name cant be short as it is a keyword.
2)argument in the main method is wrong it should be String args[]
3) variable t is declared twice
4) undefined variable i
thanku
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that you did a typo and it is int i=0; not int t=0;
Anyway, the | | operator is design so that if the firts part is true, the second part is never evaluated.
This means that the line b=(t | | ((i++) ==0)); only sets b to true, sice t is true.
The second line, where f is false, evaluates the i+=2 part, seting i to 2. Since 2 is larger then 0, b is asigned true again.
ok?
/Mike
 
hans raj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankyou.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the Bunkhouse for good books. Also, you should compile your code before posting. It will help get more meaningful answers.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if it was int i=0; in the declaration,
then the answer is 2 when u execute the class right?
 
hans raj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
thankyou paul for ur suggestion, iam new to this site , i will certainly do it before i post some code.
Hans
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic