Search Header Logo

JAVA for loops and while loops

9th - 12th Grade

Used 118+ times

JAVA for loops and while loops
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct function of a for loop?

To check for conditions after executing the statements

To be a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.

To determine a boolean variable as true or false.

To consume the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is an Increment/ Decrement?

It initializes the variable in use.

It is used for updating the variable for next iteration.

It marks the start of a for loop.

It is used for testing the exit condition for a loop.

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is the output of the following code segment?


class forLoopDemo

{ public static void main(String args[])

{ // for loop begins when x=2

// and runs till x <=4

for (int x = 2; x <= 4; x++)

System.out.println("Value of x:" + x);

}

}

Value of x:2

Value of x:3

Value of x:4

Value of x:1

Value of x:2

Value of x:3

Value of x:2

Value of x:2

Value of x:4

Value of x:2

Value of x:3

Value of x:3

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct function of a while loop?

A control flow statement that allows code to be executed repeatedly based on a given Boolean condition.

To consume the initialization, condition and increment/decrement in one line

To initialize the variable in use.

To check for condition after executing the statements

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What is the correct output for the following code segment?


class whileLoopDemo

{

public static void main(String args[])

{

int x = 1;

// Exit when x becomes greater than 4

while (x <= 4)

{

System.out.println("Value of x:" + x);

// Increment the value of x for

// next iteration

x++;

}

}

}

Value of x:1

Value of x:2

Value of x:4

Value of x:1

Value of x:2

Value of x:3

Value of x:1

Value of x:2

Value of x:3

Value of x:4

Value of x:2

Value of x:2

Value of x:3

Value of x:4

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What are 3 general types of loops in Java?

for loops, while loops and do loops

while loops, do loops and hit loops

kin loops, for loops and multi loops

for loops, while loops and multi loops

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What must the test be so that the following fragment prints out the integers 5 through and including 15?


for ( int j = 5; ________ ; j++ )

{

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

}

System.out.println( );

j<15

j<=16

j<16

j==15

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?