This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Crazy Loops!!

 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am doing a Log book for uni, which keeps usual information of java to use throughout the next three years. I am just wondering how the following loops would be done.
To understand more.



 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, there are no loops in the code above - only conditionals.
Second, I don't understand your question . What excatly are your doubts about the code?
 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the results of the three code segments are quite clear:
Segment one: the value won�t be printed out.
Segment two: the value won�t be printed out.
Segment three: the output should be twenty four.
My understanding to these three code segments is: Maybe they are illustrating some basic logic implementing with Java.
 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the output of the first given example will by 21. This is becaue you want to output the value of VALUE if the value is greater than 30 (false), OR if it is less than 40 (true). Since one is true, then the expression evaluates to true, and the value will be printed.
The second given code will have no output, since MIN is set to the value of VALUE, it can't possibly be less than VALUE. There are no else statements, so nothing can be printed, and execution would simply continue past the entire block.
The last code example would produce 24 as it's output. Be careful with switch blocks, because if there had not been a BREAK statement after the increment in the 20's case, then the output would have been 26. The switch would have dropped through to the 40's case and added another 2 to the total.
Hope this helps some, and that it's not entirely incoherent )
 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin's answer is perfect!
Don't think things too hard, but think them in different angels.
[ January 03, 2003: Message edited by: Melliholic Michael ]
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first code :
result is 21
second code :
result is no_result
third code :
result is : 24
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
Divya Venkatesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u please make your question more clear.
Regards :
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic