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
PRACTICE SQUARES CUBES TRIPLETS MULTIPLICATION PATTERNS

Flashcard
•
12th Grade - University
18 questions
APCSA Unit 2 Review

Flashcard
•
Professional Development
15 questions
Multiplication Facts

Flashcard
•
KG - University
8 questions
Methods

Flashcard
•
University
10 questions
C++ Programming Characteristics and Features

Flashcard
•
University
6 questions
décimo terceiro sábado ( ingleses)

Flashcard
•
KG
10 questions
Java Exception Handling

Flashcard
•
11th - 12th Grade
10 questions
Output in Java

Flashcard
•
11th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Appointment Passes Review

Quiz
•
6th - 8th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
Grammar Review

Quiz
•
6th - 9th 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
10 questions
Capitalization

Quiz
•
KG - 9th Grade
8 questions
Place Value & Value

Quiz
•
KG - 2nd Grade
20 questions
Capitalization in sentences

Quiz
•
KG - 4th Grade
12 questions
Continents and Oceans

Quiz
•
KG - 8th Grade
20 questions
Add & Subtract to 10

Quiz
•
KG - 2nd Grade