JAVA for loops and while loops

JAVA for loops and while loops

9th - 12th Grade

10 Qs

quiz-placeholder

Similar activities

LOOPS(Pascal)

LOOPS(Pascal)

11th Grade

13 Qs

LOOPS

LOOPS

7th - 9th Grade

10 Qs

while loop

while loop

9th Grade

10 Qs

Advanced Java Study Guide

Advanced Java Study Guide

11th - 12th Grade

10 Qs

Loops

Loops

9th - 12th Grade

10 Qs

Loops

Loops

10th Grade

15 Qs

Abs. Value Eq. and Ineq.

Abs. Value Eq. and Ineq.

12th Grade

13 Qs

Nested loops

Nested loops

8th - 9th Grade

10 Qs

JAVA for loops and while loops

JAVA for loops and while loops

Assessment

Quiz

9th - 12th Grade

Medium

Used 110+ times

FREE Resource

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

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?