Site icon DataFlair

Quiz on Java For Loop

quiz on java for loop

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Mastering the `for` loop is a fundamental rite of passage for any Java programmer. This cornerstone loop structure empowers you to execute a block of code repeatedly, a capability that forms the backbone of many powerful programming techniques.

From iterating through massive datasets and collections to precisely controlling the flow of your program, the `for` loop plays a critical role in solving a wide range of programming challenges.

This engaging quiz provides the perfect opportunity to test your understanding of how to harness the power of `for` loops in Java, regardless of your experience level. Are you ready to dive in and showcase your `for` loop expertise?

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

     Which of the following is not a type of for loop ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class ForLoop {

    public static void main ( String args [ ]  )

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

    {

    System.out.println(i);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class Loop {

    public static void main ( String args [ ] )

    {

    for ( i = 10 ; i < 5 ; i — )

    {

    int a;

    System.out.println(a);

    }

    }

    How many times the null value is printed ?

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following is the syntax of for loop ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class ForEach {

    public static void main ( String args [ ] )

    {

    int [ ] a = { 1 , 2 , 3 , 4 , 5 };

    for( int i : a )

    {

    System.out.println(i);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class Matrices {

    public static void main ( String args [ ] )

    {

    for( int i = 1 ; i < 3 ; i ++ )

    {

    for ( int j = 1 ; j < 3 ; j ++ )

    {

    System.out.println ( i + “ “ +  j );

    }

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following is true about Labeled for loop in Java ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class Error {

    public static void main ( String args [ ] )

    {

    for( int i = 0 ; i < 3 ; i — )

    {

    System.out.println(i);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    class Sample {

    public void display(String a )

    {

    for ( i = 0 ; i < 3 ; i ++ )

    {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Sample obj = new Sample();

    obj.display(“DataFlair”);

    }

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    To display all the elements in an array, which of the following for loop is used ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Nested {

    public static void main ( String args [ ] )

    {

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

    {

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

    {

    System.out.println(i);

    }

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    class Label {

    public static void main ( 

    one:

    for( i = 1 ; i < = 5 ; i ++ )

    {

    two:

    for( j = 0 ; j < 3 ; j ++ )

    {

    System.out.println(j);

    }

    break two;

    System.out.println(i);

    }

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which of the following statements can be used in a for loop ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    class Main {

    public static void main ( String args [ ] )

    {

    String names [ ] = { “ Sachin “ , “Dhoni “ , “Virat” };

    for(names[ ] )

    {

    System.out.println(names);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

     class LoopingStatement {

    public void method( int i ) 

    {

    for ( i ; i < 3 ; i ++ )

    {

    System.out.println(“DataFlair”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    LoopingStatement s = new LoopingStatement();

    s.method(2);

    }

    }

    How many times will the String DataFlair be printed ?

    Correct
    Incorrect

Summary:

Congratulations on conquering the Java `for` loop quiz! Now’s the perfect time to take a deep breath and reflect on your performance. Were there any particular concepts that challenged you? Don’t worry if so! Mastering `for` loops is essential for crafting powerful and efficient Java programs, and encountering a bump in the road is a normal part of the learning process.

This quiz is designed to be a valuable tool – revisit it as often as needed to solidify your understanding. Feeling up for more Java adventures? We’ve got you covered! Dive deeper into the world of `for` loops with our extensive library of resources, including in-depth tutorials, comprehensive online courses, and engaging practice problems.

The more you explore and experiment, the more confident and skilled you’ll become as a Java programmer. So keep at it, keep learning, and keep building amazing Java applications!

Exit mobile version