Loop Practice Exam Questions & Answers 2024/2025
What is the output?
for(int i = 0; i <= 5; i++){
Sln("Big Numbers! "+ i*2);
} - ANSWERSBig Numbers! 0
Big Numbers! 2
Big Numbers! 4
Big Numbers! 6
Big Numbers! 8
Big Numbers! 10
Is this a valid loop?
for(int i = 0, i <= 4, ...
} - ANSWERSNo, the variables in the loop are separated by semicolons not commas.
How many times will this loop execute?
for(int p = 2; p < 4; p++){
} - ANSWERS2 Times
What is the output?
for(int i = 5; i >= 1; i--){
, System.out.print("haha");
} - ANSWERShahahahahahahahahaha
Is this a valid loop?
for(int i = 0; i <= 4; i++;){
} - ANSWERSNo, there shouldn't be a semicolon by the last variable (i++)
The purpose of a loop is to... - ANSWERSRepeat operation(s) many times
What is the output?
for(int i = 5; i > 0; i-- ){
int mysteryInt = 100;
mysteryInt -= i;
System.out.print(mysteryInt + ", ");
} - ANSWERS95, 96, 97, 98, 99,
What is the output?
for(int i = 0; i <= 6; i++){
for(int j = 1; j <= 7-i; j++){
System.out.print("*")
}
System.out.println("");
} - ANSWERS*******
******
*****
****
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Bensuda. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for £6.57. You're not tied to anything after your purchase.