1.
How many times will “hello world” be printed in the following program: int count = 0; while (count < 10) { System.out.println(“Hello World”); count++; }
2.
How many times will “hello world” be printed in the following program: int count = 10; while (count < 1) { System.out.println(“Hello World”); count++; }
3.
How many times will “I love Java Programming !” be printed in the following program segment? int count = 10; while (count >= 10) { System.out.println(“I love Java Programming !”); count++; }
4.
How many times will “I love Java Programming !” be printed in the following program segment? int count = 0; while (count < 10) { System.out.println(“I love Java Programming !”); }
5.
The code below is supposed to print the integers from 10 to 1 backwards. What is wrong with it? count = 10; while (count >= 0) { System.out.println(count); count = count + 1; }
6.
Consider the following loop: final int LIMIT = 16; int count = 1; int sum = 0; int nextVal = 2; while (sum < LIMIT) { sum = sum + nextVal; nextVal = nextVal + 2; count = count + 1; }
sum
nextVale
count
•
Trace this loop, that is, in the table next to the code, show values for variables nextVal, sum and count at each iteration.
7.
Create a project called LetterInput. The Main class will use a while loop to continue asking the user for a single character. The loop will stop iterating when the user enters the letter Q or q (upper or lower case). If the letter T/t or P/p (again upper or lowercase) is entered, print the message “Invalid letter” to the screen and ask user to enter another letter. At the end, print out the total number of valid letters the user has entered.
8.
Create a project named Grades. In the Main class, use a while loop to continue asking the user for a student score. From this score, calculate and print the letter student’s grade based on the range: 100 – 90: A 89.99 – 80: B 79.99 – 70: C 69.99 – 60: D 59.99 – 0: F Your program should handle decimal scores. The loop will stop iterating when the user enters n for no. Finally, after all the student scores have been entered, calculate the average score. An example is: Please enter a new Score: 75.8 75.8 is a C Continue? (yes/no): yes Please enter a new Score: 82.0 82.0 is a B Continue? (yes/no): yes Please enter a new Score: 93.12 93.12 is an A Continue? (yes/no): no The average score is 83.64