Nested Loop MCQs
Nested Loop MCQs
Question 1
Which java concept does the following picture depicts?
Question 2
int i, j;
for(i =1; i <= 6; i = i + 3)
{
for(j = 5; j > 3; j--)
{
System.out.print(i);
}
}
Question 3
int i, j;
for(i = 7; i >= 4; i = i-2)
{
for(j = 1;j <= i-5; j++)
{
System.out.print(j);
}
Question 4
ASSERTION (A): In a Nested loop, If the outer loop is not executed, the inner loop will not get executed at all.
REASON (R): In a Nested loop, the outer loop takes control of the repetitions of the inner loop.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is false and Reason (R) is true
Question 5
int i, j, s = 0;
for(i = 2; i <= 6; i = i + 2)
{
for(j = i; j >= 0; j = j-2)
{
s = s + j;
}
}
System.out.print(s);
a)22 b) 18 c)20 d) 0
Question 6
int i, j = 0, s = 0;
for(i = 1;i <= 6; i++)
{
for(j = 1; j <= i; j++)
{
s = s + ++j;
}
}
System.out.print(j + " " + s);
Question 7
ASSERTION (A) : In a Nested loop, , if the outer loop is executed, the inner loop may or may not get executed.
REASON (R) : The inner loop’s execution , depends on the test-condition it is evaluating.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
Question 8
char i , j;
for(i = 'A'; i <= 'C'; i++)
{ for(j = 'D'; j >= i ; j--)
{
System.out.print((int)j + ",");
}
System.out.println();
}
a) 68,67,66,65, b) 68,67,66,65 c) 68,67,66,65, d) 68,67,66,
68,67,66, 68,67,66, 68,67,
68,67,
Question 9
Read the following code and choose the correct answer.
int i, j;
for (i = 1; i <= 2;i++)
{
for(j = 1;j <= 3; j++)
{
if(j == 2)
break;
else
System.out.println(j + ","); }}
Question 10
for(i = 1; i <= 5; i++);
{
for(j = 1; j <= i; j = j + 2);
{
System.out.print(j);
}
}
a) no output b) 7 c)9 d) 5