There are certain sets of code containing loops that we use over and over (algorithms)
That is what you did last time with Lesson 12 Q6.
Write a program to ask the user for input to represent the result of the throw. Find the sum of the numbers and then the average. Use Q as a sentinel value.
import java.util.Scanner; public class InputTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double value = 0; double sum = 0; int count = 0; System.out.print("Enter a number. Q to quit: "); while (scan.hasNextDouble()) { value = scan.nextDouble(); sum = sum + value; count++; System.out.print("Enter a number another number. Q to quit: "); } System.out.println("Sum: " + sum); double average = 0; if (count > 0) { average = sum / count; } System.out.println("Average: " + average); } }
Record your participation in Piazza clicker question Lesson13 Q1
Write a program to get the height of students from the user as a double and find the average height of all the students in a group.
You can use input_practice.zip from last lesson to save time
Let's visually find the tallest in a group of students.
Record your participation in Piazza clicker question Lesson13 Q2
On a piece of paper or in a text editor, write simple pseudocode to find the shortest student in a set of students. Just write the algorithm. Don't worry about input or output
Record your participation in Piazza clicker question Lesson13 Q3
Using this pseudocode for finding the minimum, write a program to get a set of heights from the user. Terminate when a non-number is entered. Then print the minimum height (the shortest). You can use input_practice.zip.
Declare a variable to hold the minimum Prompt the user to enter a height minimum = nextDouble() Prompt the user to enter a height or q to quit While another double has been entered read a value for height if the height is less than the current minimum Set the value of minimum to height Prompt again Print the minimum
Let's visually count the number of students 5.5 feet tall or taller.
Record your participation in Piazza clicker question Lesson13 Q4
Write the pseudocode of an algorithm to determine how many students are 5.5 feet tall or taller.
Record your participation in Piazza clicker question Lesson13 Q5
Write a program to determine how many students are 5.5 feet tall or taller. Starter code is in count_matches_project. It does the input for you. You need to add the counting matches algorithm code.
Record your participation in Piazza clicker question Lesson13 Q6
How would you write a loop that will not terminate. That means the condition will alwas be true.
Find the position of the first space in a string using a loop
boolean found = false; String ch = "?"; int position = 0; while (!found && position < str.length()) { ch = str.substring(position, position + 1); if (ch.equals(" ")) { found = true; } else { position++; } }
Record your participation in Piazza clicker question Lesson13 Q7
Write a program to ask the user for a string (use nextLine()). Then find and print the position of the first @. Here is another link to input_practice.zip We are practicing loops so use a loop.