Search Header Logo

Java - decision making and looping

Authored by Sowparnika A

Computers

University

Used 1+ times

Java - decision making and looping
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 will be the output of the following Java code?

int a = 10, b = 20;

if (a < b) { if (b > 15)

{

System.out.println("TRUE");

} else

{

System.out.println("FALSE");

}

}

else

{

System.out.println("NONE");

}

TRUE


FALSE

NONE

Compilation error

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How does a while loop start?

The loop executes the block of code if the condition is false.

The loop executes the block of code at least once before checking the condition.

The loop executes the block of code if the condition is true.

The loop condition is checked after executing the block of code.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the following code print?

int i = 0;

while (i < 3)

{

System.out.println("Hi");

i++;

}

Hi

Hi printed 3 times

Hi printed 4 times

The code results in an infinite loop

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the use of the break statement in loops?

It terminates the loop and transfers execution to the statement immediately following the loop

It skips the current iteration of the loop and continues with the next iteration.

It causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

It is used to return a value from a method with a non-void return type.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will the following switch statement output for int day = 4; ?

switch (day)

{

case 1:

System.out.println("Monday");

break;

case 2: System.out.println("Tuesday");

break;

case 3: System.out.println("Wednesday");

break;

case 4: System.out.println("Thursday");

break;

case 5: System.out.println("Friday");

break;

default: System.out.println("Weekend");

}

Monday

Tuesday

Thursday

Weekend

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code ?

int i = 10;

do

{

System.out.println(i);

i--;

} while (i > 10);

Prints 10

Prints numbers from 10 to 1

No output

Compilation error

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following for loop declarations is valid in Java?

for (int i = 0, i < 5; i++)

{

}

for (int i = 0; i < 5; i++)

{

}

for i = 1 to 10

{

}

for (int i; i < 5; i++)

{

}

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?

Discover more resources for Computers