Java - decision making and looping

Java - decision making and looping

University

10 Qs

quiz-placeholder

Similar activities

Java Static

Java Static

University

10 Qs

Inheritance

Inheritance

University

10 Qs

Loops-2

Loops-2

University

15 Qs

LOOPS IN C++

LOOPS IN C++

10th Grade - University

10 Qs

Java Quiz 2

Java Quiz 2

University

15 Qs

JAVA array

JAVA array

12th Grade - University

10 Qs

Java Control Flow and Collections

Java Control Flow and Collections

University

10 Qs

Java Programming

Java Programming

University

15 Qs

Java - decision making and looping

Java - decision making and looping

Assessment

Quiz

Computers

University

Hard

Created by

Sowparnika A

Used 1+ times

FREE Resource

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++)

{

}

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?