Advertisement
Sc2ad

Lecture Notes- 9/6/16

Sep 6th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. Today we went over while loops:
  2. Notation:
  3. while (condition) {
  4. // DO ...
  5. }
  6. The goal was to add to your previous assignment from yesterday and add a new method to your 'child' class:
  7. 1. It should have a return type of void
  8. 2. It can be any name you wish
  9. 3. One parameter, which represents the target of the while loop
  10. 4. In the method, create one variable and set it to 0
  11. 5. Use a while (true) { ... } loop and increment to that variable until it is equivalent (or greater than) the target parameter.
  12. 6. Once that is true, break out from the while loop (Hint: use break;)
  13. 7. Then print the number of times the while loop ran (Hint: Print the variable you were adding to every time the while loop ran)
  14. 8. Use this method in your main class and main method.
  15. BONUS: Change your other method (The getInput() Method) so that it asks the user for a number. Then in your parent class, it takes that number and runs the other method using that number.
  16.  
  17. Please don't be scared if you don't understand this. We will be going over this in more depth tomorrow (when I get access to the white board again).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement