Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Today we went over while loops:
- Notation:
- while (condition) {
- // DO ...
- }
- The goal was to add to your previous assignment from yesterday and add a new method to your 'child' class:
- 1. It should have a return type of void
- 2. It can be any name you wish
- 3. One parameter, which represents the target of the while loop
- 4. In the method, create one variable and set it to 0
- 5. Use a while (true) { ... } loop and increment to that variable until it is equivalent (or greater than) the target parameter.
- 6. Once that is true, break out from the while loop (Hint: use break;)
- 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)
- 8. Use this method in your main class and main method.
- 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.
- 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