Explore BrainMass

Explore BrainMass

    Java loops

    This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

    1

    What will be the output of this loop (assume all variables are declared properly and there are no syntax errors):

    for (i=0;i<10;i++)
    System.out.println(i);

    2

    What will be the output of this loop (assume all variables are declared properly and there are no syntax errors):

    i=0;
    while (i<=10) {
    System. out.println(i);
    i = i+2;
    }

    3

    What will be the output of this loop (assume all variables are declared properly and there are no syntax errors):

    i=10;
    while (i<10) {
    System. out.println(i);
    i = i+2;
    }

    4

    What will be the output of this loop (assume all variables are declared properly and there are no syntax errors):

    i=0;
    while (i<=10) {
    System. out.println(i);
    }

    5

    What will be the output of this loop (assume all variables are declared properly and there are no syntax errors):

    for (i=0;i<10;i=i+5)
    System.out.println(i);