0% found this document useful (0 votes)
14 views

Class X Nested Loops

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Class X Nested Loops

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CLASS X

COMPUTER WORSHEET
TOPIC: NESTED LOOPING
Q1: Select the correct option for the following.

a) Examine the following code , the select the output:


int i,j;
for(int i=5;i<=7;i=i+2)
for(int j=5;j<=i;j=j+2)
System.out.println(j);
System.out.println(i);
i)5 ii) 5 iii) 5 iv) 5
5 7 7 5
7 9 7 7
9 9 7
b) Loops are:-
i) Repetition block that executes a group of statements repeatedly.
ii) Loop is usually executed as long as a condition is met
iii) Both i and ii are correct.
iv) i is true and ii is false.
c) which loop is faster in java language?
i) for ii) while iii)do….while iv) All work at same speed
d) For loop in java programs, if the condition is missing?
i) it is assumed to be present and taken to be false.
ii) it is assumed to be present and taken to the true.
iii) it results in a syntax error.
iv) execution will be terminated abruptly.
e) Which situation is best suited for nested loops?
i) Calculating logarithmic data.
ii) Displaying output.
iii) Working with one dimensional arrays.
iv) Working with multi dimensional arrays.

Q2: Differentiate between the following:-

a) Update expression of for loop and update expression of while loop.


b) Inner loop and outer loop

Q3: State whether the following statements are true or false:

a) Break statement helps to terminate both inner and outer loops.


b) Inner loops always execute one times more than outer loops.

Q4: Give the output for the following:

a) int y,p;
for (int x=10; x<=30; x++)
{for (y=15; y<=20; y++)
{p = x * y;
System.out.print(p);}
System.out.println( );}

b)int w=6;
for (int x=2; x<=6; x++)
{for (int y=1; y<=5; y++)
{if (w%y==0)
break;
System.out.print(y);}
w=w*2;
System.out.println(w);}

Q5: Write the programs in java to print the following patterns.


a) AZBYCXDWEV
AZBYCXDW
AZBYCX
AZBY
AZ
b) 1010101010
32323232
545454
7676
98
Q6: Write the programs to print the followings series:-
1,2,2,4,8,12…………
Q7: Design a class with the following details
Class: pattern
Data members:
n,x integer variables
Data function:
pattern()- default constructor
void input()- input the values of n and x
void print1()- if x=5, and n=4
then the pattern is
5
25
125
625
void print2() if x=5, and n=4
20161284
161284
1284
84
4
Also write the main method().
Q7) Rewrite the given code to print the desired outputs after filling the blanks.

a) To print the following pattern


54321
4321
321
21
1
The code is
for(int i=5;_________;i--)
{
for (_____;j>=1;_____)
System.out.print(j);
}
System.out.print();

b) To print the following pattern


54321
4321
321
21
1
The code is
for(int i=1;_________;i++)
{
for (_____;j>=1;_____)
System.out.print(j);
}
System.out.print();

c) To print the following pattern


54321
5432
543
54
5
The code is
for(int i=5;_________;i--)
{
for (_____;_____;j--)
System.out.print(j);
}
System.out.print();

d) To print the following pattern


97531
9753
975
97
9
The code is
for(int i=9;_________;i=i-2)
{
for (_____;j>=i;_____)
System.out.print(j);
}
System.out.print();

e) To print the following pattern

97531
9753
975
97
9
The code is
for(int i=1;_________;i=i+2)
{
for (_____;j>=i;_____)
System.out.print(j);
}
System.out.print();

***********************************************************************************

You might also like