Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBat Array Problem (larger value w/o loop)

 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • 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!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic