Sunday 16 December 2018

Class 9 - continue statement

1.
     for (int i = 1; i <= 5; ++i) 
{      
         if (i > 5)
         {
            continue;
         }      
         System.out.println(i);
}
The output for the above code fragment is
1
2
3
4
5
when the value of i is greater than 5, the control will go to the next iteration, so from 6 to 10 will not be printed.

2. 

for (int i = 1; i <= 10; ++i)
 {     
         if (i > 4 && i < 9)
        {
            continue;
         }     
         System.out.println(i);
      }  
The output will be 
1

2
3
4
9
10

Sunday 9 December 2018

Class 9 - Loop revision

Points to remember :
1. break statement is used to break the loop.
2. continue sends the control to the update expression.
3. for loop is used for fixed iterations.That is where you know the final limit.
4. In while loop, condition is tested before execution.
5. The do while loop executes the statements atleast once even if the condition is false.
6. Infinite loop : control does not reach the test condition.
7. Empty loop : loop does not contain any statement in the body.


1. What will be the output for the following programs:
i)
            for(a=0;a<30;a++)
           {
                   if(a==5)
                   break;
                   System.out.print(+a);
          }

ii)
      for(x=1;x<=5;x++)
      {
           if(x==2)
          continue;
          if(x==4)
          continue;
System.out.println(x);
      }
iii)
        int x=0;
       while(x<=10)
        {
               x++;
             if(x==4)
              break;
             System.out.println(x);
        }
2. Differentiate : while and do while.
3.Write a program to enter a number and print the sum of odd numbers and even numbers for the first n natural numbers.                                                                     [ICSE]
4.
      i)         12+22+32+42+…………+n2
      ii)     x2/2+x3/3+………xn/n

1. Fibonacci series:
 0,1,1,2,3,5,8.............................
2. Prime number:
    The divisors are one and the number itself.
    e.g : 5 : divisors 1 and 5
3. Perfect number :
     The sum of the divisors(excluding the number) equal to the number itself.
    e.g : 6
       divisors are 1+2+3=6
4. Armstrong number:
    e.g :
         153=13+53+33
               =1+125+27
               =153
5. Palindrome number:
  e.g:
        272: reverse the number 272.