Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Write a while loop to print numbers 1 through 5.
Remember to initialize a counter variable and increment it.
What will be printed by the following code?
int j = 1;
while (j < 4) {
System.out.println(j);
j++;
}Count how many times the loop runs based on the condition.
What is a while loop?
Think about how the loop behaves based on conditions.
True or False: A while loop can run zero times.
Consider the condition's role in starting the loop.
Write a while loop that simulates a basic login system that exits after three failed attempts. Output whether the user succeeded or failed.
Keep track of the number of attempts and check against a predetermined password.
Create a while loop that takes numbers from user input until a negative number is entered, then outputs the sum of all positive numbers entered.
Use a variable to accumulate the sum of positive numbers and set a condition to stop when a negative number is entered.
5 more questions in this section. Enroll free to practise them all.
Enroll free