• 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

Are any of these wrong?

 
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
FullSizeRender.jpg
[Thumbnail for FullSizeRender.jpg]
 
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post text instead of an image?

Also please post the manual steps you took to find the answers. For example:
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the fourth one may be incorrect.... and BTW, please QuoteYourSources.

Henry
 
Norm Radder
Rancher
Posts: 5008
38
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that is java code, why not write a small testing program that can be executed and show you the answer?
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


When i run this it outputs nothing anybody know why? i ran the others and they where right except for this one  
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are missing {} following some of the if statements.  Edit the code and add the missing {}s so you can see the code's logic better.

Note: You should always use {}s with if statements and loops and anywhere a block of code can be controlled by a single statement.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alvaroo Hernandez wrote:
When i run this it outputs nothing anybody know why? i ran the others and they where right except for this one  



There is no output because none of the conditions are satisfied. This includes the condition that sets the value to 99. This is why your answer to the fourth one is incorrect.

Henry
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

none of the conditions are satisfied

'
Depending on what if  the else is connected to.   Missing {}s can make the code harder to read and understand.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:
Depending on what if  the else is connected to.   Missing {}s can make the code harder to read and understand.



Perhaps... but the OP's code does match the picture provided (in the initial post), which we have to assume is correct.

And BTW, to the OP, again, please QuoteYourSources.

Henry
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Depending on what if  the else is connected to

'else' being connected to nearest 'if' in case of missing curly braces.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alvaroo Hernandez wrote:
When i run this it outputs nothing anybody know why? i ran the others and they where right except for this one  


I don't know if you realize what is happening on lines 11, 13, 16, and 18.  The expression that you are passing to System.out.print() is an assignment expression which is first executed. The value passed to print() is the value assigned to d. It appears to work but there is one flaw in this: when the condition on line 15 is false, execution does not fall through to the else on line 17 because that else is part of the if-statement on line 14. You probably thought otherwise and expected line 18 to be executed, so you answered 99.  In this case, none of the System.out.print() statements will be executed so you will not get any output.  

If you do this instead, you will get the output that will show you the answer for any case.

 
Norm Radder
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like its the case of the missing else.
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!! i can see where it went wrong since the value for d was already established and since none of the statements were satisfied it should be 44. I feel dumb right now how did i not catch that   Thanks again everyone as i am barely learning java i will get the hang of it with time  
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic