0% found this document useful (0 votes)
33 views3 pages

Nested Loop MCQs

The document is a worksheet containing multiple-choice questions (MCQs) focused on nested loops in Java programming. It includes questions about code snippets, assertions and reasons related to nested loops, and expected outputs of various code segments. Each question provides four answer options for selection.

Uploaded by

sumanpratham5555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Nested Loop MCQs

The document is a worksheet containing multiple-choice questions (MCQs) focused on nested loops in Java programming. It includes questions about code snippets, assertions and reasons related to nested loops, and expected outputs of various code segments. Each question provides four answer options for selection.

Uploaded by

sumanpratham5555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

NESTED LOOPS WORKSHEET 1 (MCQs)

Question 1
Which java concept does the following picture depicts?

a) flower circles b) nested loops c) a circle d) exit controlled loop

Question 2
int i, j;
for(i =1; i <= 6; i = i + 3)
{
for(j = 5; j > 3; j--)
{
System.out.print(i);
}
}

a) 5454 b) 543 c)123456 d) 1144

Question 3
int i, j;
for(i = 7; i >= 4; i = i-2)
{
for(j = 1;j <= i-5; j++)
{
System.out.print(j);
}

a) 1,2, b) 1,2,3, c)1, d) 1,2,4,

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);

a)7 34 b)7 40 c)6,40 d) 6 34

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 + ","); }}

a) When executed both the loops will be terminated as soon as j = 2.


b) When break is executed inside the inner loop the outer loop remains unaffected.
c) else should not be used after break.
d) The output will be 1, 1.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy