ClassEx While Loop
ClassEx While Loop
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:
3. How many times will “I love Java Programming !” be printed in the following program segment?
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;
}
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:
Continue? (yes/no):
yes
Continue? (yes/no):
yes
Continue? (yes/no):
no