Search Header Logo

Introduction to While Loops

Computers

9th - 12th Grade

Used 2+ times

Introduction to While Loops
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What is the output of the following code?

int x = 0;

while (x < 4) { x = x + 1;}

System.out.println("x is " + x);

0

1

3

4

2.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

What will be displayed when the following code is executed?

6 3 0

6 3

3 0

0

3.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What will be the output of the following code?


int x = 0;


while( x > 0 ) {

System.out.print( x + " ");

x++; }

0 0 0 0 0

1 2 3 4 5

0 1 2 3 4

0 1 2 3 4 5 ... infinite loop

4.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What is the output of the code?


int num = 1;


while ( num < 10 ) {

num += 2;

System.out.print( num + " "); }

3 5 7 9 11

3 5 7 9

1 3 5 7 9 11

1 3 5 7 9

5.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What should go in place of /*missing code*/ so that the program only accepts the name "Bill" as the correct username?


String name = scan.next();


while( */ missing code */ ) {

System.out.print("Please enter the correct username: ");

name = scan.next();

}


//username is correct

System.out.println("Welcome Bill!");

name == "Bill"

name != "Bill"

name.equals("Bill")

!(name.equals("Bill"))

6.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What is the value of sum at the completion of the code?


int val = 0;

int sum = 0;


while (num <= 8 ) {

sum += num;

num++; }

sum = 36

sum = 28

sum = 42

infinite loop

7.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

What is the value for x at the completion of the program?


int x = 1;

while( x < 100 ) {

x = x + x;

System.out.print(x + " "); }

64

128

99

100

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?