filmov
tv
APCSA Practice: What Does This Java While Loop Print? 💻

Показать описание
📢 What is the output of the following code?
java
Copy
int x = -5;
while (x less than 0) {
x++;
}
Options:
A) 5 4 3 2 1
B) -5 -4 -3 -2 -1
C) -4 -3 -2 -1 0
D) 4 3 2 1 0
📝 Solution Breakdown:
1️⃣ The variable x is initialized to -5.
2️⃣ The while loop continues running as long as x less than 0.
3️⃣ In each iteration, x is incremented by 1 and printed.
4️⃣ The loop prints -4 -3 -2 -1 0.
🔥 Final Answer: Option C — -4 -3 -2 -1 0
🔑 Key Takeaway:
The loop increments x from -5 to 0, printing each value in sequence.
#Java #WhileLoop #JavaCoding #LearnJava #Programming #APCSA
java
Copy
int x = -5;
while (x less than 0) {
x++;
}
Options:
A) 5 4 3 2 1
B) -5 -4 -3 -2 -1
C) -4 -3 -2 -1 0
D) 4 3 2 1 0
📝 Solution Breakdown:
1️⃣ The variable x is initialized to -5.
2️⃣ The while loop continues running as long as x less than 0.
3️⃣ In each iteration, x is incremented by 1 and printed.
4️⃣ The loop prints -4 -3 -2 -1 0.
🔥 Final Answer: Option C — -4 -3 -2 -1 0
🔑 Key Takeaway:
The loop increments x from -5 to 0, printing each value in sequence.
#Java #WhileLoop #JavaCoding #LearnJava #Programming #APCSA