Which looping construct is illustrated below?
for (int i=0; i<5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i));
}
CMP128 Java Ch. 04 Loops Pt. 2

Flashcard
•
Computers
•
University
•
Hard
Quizizz Content
FREE Resource
Student preview

10 questions
Show all answers
1.
FLASHCARD QUESTION
Front
Back
A count-controlled quantifiable pre-test loop
2.
FLASHCARD QUESTION
Front
Which looping construct is illustrated below?
int num = 1;
char keepSquaring = 'Y';
do
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
while (keepSquaring == 'Y' || keepSquaring == 'y');
Back
Event-driven qualifiable Post-Test Loop
3.
FLASHCARD QUESTION
Front
Which looping construct is illustrated below?
int num = 1;
char keepSquaring = 'Y';
while (keepSquaring == 'Y' || keepSquaring == 'y')
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
System.out.print("Would you like to square another number? (Y/N): ");
keepSquaring = keyboard.nextLine().charAt(0);
}
Back
Event-driven qualifiable Pre-Test Loop
4.
FLASHCARD QUESTION
Front
What is wrong with the following loop?
int num = 1;
char keepSquaring = 'Y';
while (keepSquaring == 'Y' || keepSquaring == 'y')
{
System.out.println ("The square of " + num + " is: " + (num*num) + "\n");
num++;
Back
It is missing an update statement, so the loop is infinite.
5.
FLASHCARD QUESTION
Front
What is wrong with the following loop?
for (int i=0; i>5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
Back
This loop will never execute the loop body because the counter variable starts at 0 and immediately fails the test of >5.
6.
FLASHCARD QUESTION
Front
What is wrong with the following loop?
for (int i=10; i>0; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
Back
It creates an infinite loop because i will never be less than or equal to 0.
7.
FLASHCARD QUESTION
Front
What is wrong with the following looping structure?
for (int i=0; i<5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i) + "\n");
}
Back
Nothing. It is perfect.
Create a free account and access millions of resources
Similar Resources on Quizizz
10 questions
Arrays

Flashcard
•
10th - 12th Grade
10 questions
Arrays

Flashcard
•
10th - 12th Grade
10 questions
Ôn tập chủ đề F

Flashcard
•
KG
7 questions
Demo Flashcardizz_gestes de base

Flashcard
•
Professional Development
11 questions
Computer Programming

Flashcard
•
University
3 questions
Java Classes & Objects

Flashcard
•
University
12 questions
Topic 1 C++ Programming

Flashcard
•
12th Grade
10 questions
Flashcard1-Intro-to-Java

Flashcard
•
University
Popular Resources on Quizizz
15 questions
Multiplication Facts

Quiz
•
4th Grade
20 questions
Math Review - Grade 6

Quiz
•
6th Grade
20 questions
math review

Quiz
•
4th Grade
5 questions
capitalization in sentences

Quiz
•
5th - 8th Grade
10 questions
Juneteenth History and Significance

Interactive video
•
5th - 8th Grade
15 questions
Adding and Subtracting Fractions

Quiz
•
5th Grade
10 questions
R2H Day One Internship Expectation Review Guidelines

Quiz
•
Professional Development
12 questions
Dividing Fractions

Quiz
•
6th Grade