do { statements } while (condition);
int value;
do
{
System.out.print("Enter an number < 100: ");
value = scan.nextInt();
}while (value >= 100); //tells the loop when it can execute again
Record your participation in Piazza clicker question Lesson12 Q1
Supply the code to get a positive integer from the keyboard. Keep prompting until the input is positive. Use input_practice.zip as a starter file.
Go to the beach do Put on sun screen Put down a towel Lie in the sun while the sun is shining
Walk up to the closed door do knock three times wait 30 seconds while (no one has answered)
Record your participation in Piazza clicker question Lesson 12 Q2
What does the following loop print? Make a trace tableint n = 1; while (n < 30) { n = 2 * n; System.out.print(n + " "); }
Record your participation in Piazza clicker question Lesson 12 Q3
What value is displayed by this code? Trace the code and make a trace table
Record the values of "n", "sum", and "digit" on a piece of paper or a txt file
int n = 2016; int sum = 0; while (n > 0) { int digit = n % 10; sum = sum + digit; n = n / 10; } System.out.println(sum);
Record your participation in Piazza clicker question Lesson 12 Q4
int i = 0; int sum = 0; while (sum < 10) { i++; sum = sum + i; } System.out.println( i + " " + sum);
int i = 0; int sum = 0; while (sum >= 10) { i++; sum = sum + i; } System.out.println( i + " " + sum);
int grade = 0; while (grade >= 0) { System.out.print("Enter a grade or -1 to quit: "); grade = scan.nextInt(); if (grade >= 0) { //do something with grade } }
boolean done = false; double length = 0; while (!done) { System.out.print("Enter the length or 0 to quit: "); length = scan.nextDouble(); if (length <= 0) { done = true; } else { //do something with the length } }
double temperature = 0; System.out.print("Enter the temperature, Q to quit: "); while (scan.hasNextDouble()) { temperature = scan.nextDouble(); //do something with the temperature System.out.print("Enter the temperature, Q to quit: "); }
Record your participation in Piazza clicker question Lesson12 Q5
What would happen is you entered X in the program in the last slide to input temperatures.
Record your participation in Piazza clicker question Lesson12 Q6
We are throwing a dart at a number line. (numbers can be positive, negative or zero doubles) Write a program to ask the user for input to represent the result of the throw. Find the sum of the numbers and print it. Use Q as a sentinel value. You can use input_practice.zip again as a starter
Record your participation in Piazza clicker question Lesson12 Q7
In the previous activity, you found the sum of inputs using Q as the sentinel value. Now modify the program to also find and print the average.