CMP128 Java Ch. 04 Loops Pt. 2

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

10 questions
Show all answers
1.
FLASHCARD QUESTION
Front
Which looping construct is illustrated below?
for (int i=0; i<5; i++)
{
System.out.println ("The square of " + i + " is: " + (i*i));
}
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 Wayground
15 questions
Solve Radical Equations

Flashcard
•
11th Grade
3 questions
Java Classes & Objects

Flashcard
•
University
10 questions
Arrays

Flashcard
•
10th - 12th Grade
11 questions
Ruth

Flashcard
•
Professional Development
12 questions
Code.org - Unit 6 Lists, Loops, and Traversals

Flashcard
•
10th Grade - University
15 questions
AA 3.1 REVIEW- SOLVING RADICAL EQUATIONS PRACTICE

Flashcard
•
12th Grade
15 questions
Quadratics and Complex Numbers Review

Flashcard
•
11th Grade - University
15 questions
Domain and Range

Flashcard
•
11th - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
20 questions
Disney Characters

Quiz
•
KG
20 questions
Place Value

Quiz
•
KG - 3rd Grade
20 questions
Logos

Quiz
•
KG
11 questions
Seasons

Quiz
•
KG - 1st Grade
10 questions
Who is that Character?

Quiz
•
KG - 5th Grade
15 questions
Short o

Quiz
•
KG - 2nd Grade
15 questions
Pronouns

Quiz
•
KG - 3rd Grade
20 questions
Punctuation Pre & Post Test

Quiz
•
KG - 2nd Grade