Show List

Quiz - Java operators, control structures and arrays - 2

59%

Public Average Score
Select the right answer for below questions:

What is the difference between break and continue in a Java loop?
Both break and continue terminate the loop
break skips the current iteration, continue terminates the loop
break terminates the loop, continue skips the current iteration
Both break and continue skip the current iteration
break terminates the loop, continue skips the current iteration

What is the output of the following code: int num = 10; switch (num) { case 5: System.out.println("Five"); break; case 10: System.out.println("Ten"); break; default: System.out.println("Invalid"); }
Five
Ten
Invalid
None of the above
Ten

What is the output of the following code: int[] numbers = {1, 2, 3, 4, 5}; for (int i = 0; i < numbers.length; i++) { System.out.println(numbers[i]); }
1
2
3
All of the above
All of the above

What is the use of the switch statement in Java?
To create a loop
To evaluate a condition and return a value based on the result
To execute a block of code based on multiple conditions
None of the above
To execute a block of code based on multiple conditions

What is the use of a Java array?
To store values of different data types in a matrix form
To store single value of different data types
To store multiple values of the same data type
None of the above
To store multiple values of the same data type

What is the value of the following expression: 10 * 3
3
33
10
30
30

What is the output of the following code: int num = 5; if (num == 5) { System.out.println("Equal"); } else { System.out.println("Not equal"); }
5
Not equal
Equal
None of the above
Equal

What is the use of the ternary operator (? :) in Java?
To execute a block of code based on a condition
To evaluate a condition and return a value based on the result
To create a loop
None of the above
To evaluate a condition and return a value based on the result

What is the difference between a for loop and a while loop in Java?
Both for and while loops can be used for any number of iterations
A while loop is used when the number of iterations is known, while a for loop is used when the number of iterations is unknown
A for loop is used when the number of iterations is known, while a while loop is used when the number of iterations is unknown
None of the above
A for loop is used when the number of iterations is known, while a while loop is used when the number of iterations is unknown

What is the output of the following code: int[] numbers = {1, 2, 3, 4, 5}; for (int i = numbers.length - 1; i >= 0; i--) { System.out.println(numbers[i]); }
1
2
5
5 4 3 2 1
5 4 3 2 1

Submit
Retry
{"qz1-506853":"break terminates the loop, continue skips the current iteration","qz1-506854":"Ten","qz1-506855":"All of the above","qz1-506856":"To execute a block of code based on multiple conditions","qz1-506857":"To store multiple values of the same data type","qz1-506858":"30","qz1-506859":"Equal","qz1-506860":"To evaluate a condition and return a value based on the result","qz1-506861":"A for loop is used when the number of iterations is known, while a while loop is used when the number of iterations is unknown","qz1-506862":"5 4 3 2 1"}

    Leave a Comment


  • captcha text