Site icon DataFlair

Quiz on Java Loops

quiz on java loops

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.

Time limit: 0

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

Quiz complete. Results are being recorded.

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

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    How many times will the loop print DataFlair ?

    1. class Sample {

    public static void main ( String args [ ] ) 

    {

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

    {

    system.out.println(“DataFlair);

    }

    }

    Correct
    Incorrect
  2. 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 );

    }

    }

     

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

     Which type of loop is used for array traversal ?

     

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following is the correct syntax for For loop ?

    Correct
    Incorrect
  5. 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);

    }

    }

    }

    Correct
    Incorrect
  6. 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);

    }

    }

    }

    Correct
    Incorrect
  7. 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”(;

    }

    }

    }

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     Which of the following is used to terminate an infinite loop in the output screen ?

    Correct
    Incorrect
  9. 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++;

    }

    }

    }

    Correct
    Incorrect
  10. 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);

    }

    }

    }

    Correct
    Incorrect
  11. 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++;

    }

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

     What is the syntax for infinite while loop ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which of the following is not true about the do – while loop ?

    Correct
    Incorrect
  14. 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);

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    What does a continue statement do in looping statements?

    Correct
    Incorrect

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.

Exit mobile version