• 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

JavaBat Array Problem (larger value w/o loop)

 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working through the Javabat exercises and I encountered one that asking me to figure out if the first value in an array of 3 is larger than the last value in the array and set all the values in the array to the larger of the two values. The kicker is it is in a section that says it can be done without using a loop construct. Now I could (easily) handle this with a if loop, and the code would work, but I can't think of a way to do with without a loop. I'm not going to copy/paste the problem, and I don't want anyone to write the code for me (I'm trying to learn here, people!) but if anyone has a brilliant, crazy, or ridiculously simple path to point me down it would be greatly appreciated!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"if" is not a loop; it's a control structure. "while", "for" and "do/while" are loops. I don't think you were asked to do this without "if".
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah. That makes my life much simpler. I'm not sure why I thought of an if statement as a loop....

Maybe I spent too long today staring blankly at code I didn't understand...
 
reply
    Bookmark Topic Watch Topic
  • New Topic