Professional Documents
Culture Documents
ClASS 9 - COMPUTER - WOOKBOOK - CHAPTER - 9 (ITERATIVE CONSTRUCT IN JAVA, PART - 1) 1
ClASS 9 - COMPUTER - WOOKBOOK - CHAPTER - 9 (ITERATIVE CONSTRUCT IN JAVA, PART - 1) 1
ClASS 9 - COMPUTER - WOOKBOOK - CHAPTER - 9 (ITERATIVE CONSTRUCT IN JAVA, PART - 1) 1
EXERCISE
Page:236
Q2. Write a for () loop statement /code to print all natural numbers from 1 to 20.
Answer : System.out.println( “ Displaying all natural numbers from 1 to 20 in
different lines”);
for( int x=1;x<=20;x++)
{
System.out.println(x);
}
Q3. Write a while() loop to print all natural numbers from 1 to 10.
Answer : System.out.println( “ Displaying all natural numbers from 1 to 10 in same
line);
int x=1;
while(x<=10)
{
System.out.print(x+ “ , ”);
x++; // x=x+1;
}
Q4. Write a do.. while() loop to print all natural numbers from 1 to 15.
Answer : System.out.println( “ Displaying all natural numbers from 1 to 15 in same
line);
int x=1;
do
{
System.out.print(x+ “ , ”);
x++; // x=x+1;
}
while(x<=15);
Page : 238
Q9. Rewrite the following code using the while () loop :
for( int x=10; x>=0 ; x--)
System.out.println(6+ “ * ” + x + “ = ” + 6*x);
System.out.println( n*10);
}