This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Crazy Loops!!

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can u please make your question more clear.
Regards :
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic