Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
In the fascinating world of Java programming, loops play a starring role! They’re like tireless workers, repeating a set of instructions over and over again until a certain condition is met.
This quiz is your personal playground to test your loop knowledge, no matter if you’re a coding whiz or just starting out. We’ll cover everything from the good ol’ for loop, your basic workhorse, to the more powerful while and do-while loops that can handle some trickier situations. Even those not-so-common labeled loops won’t be hiding!
So, are you ready to dive headfirst into a loop-tastic adventure and see how well you understand these essential building blocks of Java? Get your thinking cap on and prepare for a quiz that’s both fun and mind-bending! Buckle up, grab your keyboard, and let’s loop our way to Java mastery! Let’s test your knowledge of Loops in Java.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
How many times will the loop print DataFlair ?
- class Sample {
public static void main ( String args [ ] )
{
for (int i = 0 ; i < 100 ; i ++ )
{
system.out.println(“DataFlair);
}
}
CorrectIncorrect -
Question 2 of 15
2. Question
What is the error in the program?
class WhileLoop {
public static void main ( String args [ ] )
{
int x = 5;
while(x==5)
{
system.out.println(“Value is “ + x );
}
}
CorrectIncorrect -
Question 3 of 15
3. Question
Which type of loop is used for array traversal ?
CorrectIncorrect -
Question 4 of 15
4. Question
Which of the following is the correct syntax for For loop ?
CorrectIncorrect -
Question 5 of 15
5. Question
What will be the output of the program?
class ForEach {
public static void main ( String args [ ] )
{
String names[] = { “DataFlair”,”webservices”};
for( String name : names )
{
system.out.println(name);
}
}
}
CorrectIncorrect -
Question 6 of 15
6. Question
What will be the output of the program ?
class LabledForLoop {
public static void main ( String args [ ] )
{
loop1:
for(int i = 2; i <=4 ; i ++ )
{
loop2:
for( int j = 3 ; j < 5 ; j++ )
{
if( i ==4 && j==4){
break loop1;
}
}
system.out.println(i + “ “ + j);
}
}
}
CorrectIncorrect -
Question 7 of 15
7. Question
The given program is an example of which program ?
class ForLoop {
public static void main ( String args [ ] )
{
for(;;) {
system.out.println(“DataFlair”(;
}
}
}
CorrectIncorrect -
Question 8 of 15
8. Question
Which of the following is used to terminate an infinite loop in the output screen ?
CorrectIncorrect -
Question 9 of 15
9. Question
What will be the final value for x when it is executed ?
class DoWhileLoop {
public static void main ( String args [ ] )
{
Int x = 5;
do {
system.out.println(x);
++x;
system.out.println(x);
}
while(x==6);
x++;
}
}
}
CorrectIncorrect -
Question 10 of 15
10. Question
What will be the output of the program ?
class WhileLoop {
public static void main ( String args [ ] )
{
int x = 3;
while(x<=5) {
system.out.println(x);
}
}
}
CorrectIncorrect -
Question 11 of 15
11. Question
What will be the output of the program ?
class WhileExample {
public static void main ( String args [ ] )
{
String str=”DataFlair”;
int a=4;
while(a<str.length())
{
System.out.print(str.charAt(a));
i++;
}
}
}
CorrectIncorrect -
Question 12 of 15
12. Question
What is the syntax for infinite while loop ?
CorrectIncorrect -
Question 13 of 15
13. Question
Which of the following is not true about the do – while loop ?
CorrectIncorrect -
Question 14 of 15
14. Question
What will be the value of x printed ?
class GotoStatement {
public static void main ( String args [ ] )
{
int x = 1;
goto a;
x++;
while(x==1) {
x++;
}
a:
–x;
system.out.println(x);
}
}
CorrectIncorrect -
Question 15 of 15
15. Question
What does a continue statement do in looping statements?
CorrectIncorrect
Summary:
This quiz dives deep into the exciting world of Java loops! Get ready to test your skills with multiple choice questions that cover all the loop types you’ll need to master your coding.
From the classic for loop to the more flexible while and do-while loops, you’ll be challenged on their syntax and how to use them effectively. We won’t forget about labeled loops, those handy tools for adding control to your code.
But wait, there’s more! This quiz also throws in some brain teasers about infinite loops and the goto statement. Can you spot the code that will run forever, and do you know how to escape its grip? Take the challenge and see how well you can handle Java loops in all their glory!
By the end, you’ll be a loop master, confident in writing clean and efficient code that controls the flow of your program perfectly.
