github

Made bySaurav Hathi

MCQ Test Java: Loops and Controls

Q1:

What is the output of this java program?

class average

{

public static void main(String args[])

{

double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};

double result;

result = 0;

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

result = result + num[i];

System.out.print(result/6);         

}

}

Tags:
Section:
Core Programming
Options:
Q2:

What is the output of this java program?

class evaluate

{

public static void main(String args[])

{

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

int d[] = a;

int sum = 0;

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

    sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);

System.out.println(sum);

}

}

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this java program?

public class While

{

public void loop()

{

int x= 0;

while ( 1 ) /* Line 6 */

{

System.out.print("x plus one is " + (x + 1)); /* Line 8 */

}

}

}

Which statement is true?

Tags:
Section:
Core Programming
Options:
Q4:

What will be the output of the following java program?

public class Switch2

{

final static short x = 2;

public static int y = 0;

public static void main(String [] args)

{

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

{

switch (z)

{

case x: System.out.print("0 ");

case x-1: System.out.print("1 ");

case x-2: System.out.print("2 ");

}

}

}

}

Tags:
Section:
Core Programming
Options:
Q5:

In which of the following loops will the body of loop be executed even when condition controlling the loop is initially false?

Tags:
Section:
Core Programming
Options:
Q6:

Which of these statements is incorrect?

Tags:
Section:
Core Programming
Options:
Q7:

What is the output of this java program?

class jump_statments

{

public static void main(String args[ ])

{       

int x = 2;

int y = 0;

for ( ; y < 10; ++y)

{

if (y % x == 0)

continue; 

else if (y == 8)

break;

else

System.out.print(y + " ");

}

}

}

Tags:
Section:
Core Programming
Options:
Q8:

What will be the output of the program?

public class Test

{

    public static void main(String [] args)

    {

        int I = 1;

        do while ( I < 1 )

        System.out.print("I is " + I);

        while ( I > 1 ) ;

    }

}

Tags:
Section:
Core Programming
Options:
Q9:

What will be the output of this java program?

int I = 0;

    outer:

    while (true)

    {

        I++;

        inner:

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

        {

            I += j;

            if (j == 3)

                continue inner;

            break outer;

        }

        continue outer;

    }

System.out.println(I);

Tags:
Section:
Core Programming
Options:
Q10:

What will be the output of this java program?

int i = 0, j = 5;

tp: for (;;)

    {

        i++; 

        for (;;)

        {

            if(i > --j)

            {

                break tp;

            }

        }

        System.out.println("i =" + i + ", j = " + j);

Tags:
Section:
Core Programming
Options: