CMP128 Java Ch. 04 Loops Pt. 2

CMP128 Java Ch. 04 Loops Pt. 2

Assessment

Flashcard

Computers

University

Hard

Created by

Quizizz Content

FREE Resource

Student preview

quiz-placeholder

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?