Read the class notes on while loops. Read the section on break; continue;
Copy the program at the bottom of the while loop class note page and run it.
Write a while loop that will print out the numbers 1-50 (i.e. it loops 50 times printing out a number)
This is just marked for completion
Write a guess a number game.
a) make a random number between 1 and 100 using this code: int secret = (int) (Math.random() * 100) +1;
b) when the user enteres a guess, say if it is too high, too low or just right.
c) print out the number of guesses once the user wins.
This will be marked more carefully for formatting, variable names, etc.
Start learning how to use break;
and continue
Here's the outline of how to do it (but there is one problem you'll have to fix to get it to work)
while (true) {
if (num%3 == 0) continue;
}
Example:
n total --------------- 2 2 4 6 20 6 (multiples of 5 are ignored) 11 17 6 17 (multiples of 3 are ignored) -99 17 (exit the loop) Total = 17
Write a program that gets numbers (positive integers) from the user. Alternate between adding and subtracting each successive number. Print out the total each time. Quit when the total equals 100.
String s = keyboard.next();
char letter = s.charAt(0);