For Loop

Given below is example of For Loop. To print a series of Asteric (*) symbol in right angle triangle shape. We can make all other type of triangles using for loop or other loops(While or Do While). This is very interesting program for beginners :-)

class Triangle
{
           public static void main(String args[])
           {
                      int i, j;
                      for(i = 0; i <= 5; i++)
                      {
                                 for(j = 0; j <= i; j++)
                                 {
                                            System.out.println(" * ");
                                 }
                                 System.out.println();
                      }
           }
}


Output :

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


Exercise programs with for loop:

WAP to print the table of a number in a proper format.
WAP to find out all even number between 1 to 50.
WAP to find all odd number between 1 to 40.
WAP to find out factorial of a no.
WAP to print the reverse of a number.
WAP to find out all Armstrong number between 1 to 1000.
WAP to check whether a number is palindrome or not.
WAP to print all palindrome number between 1 to 100.
WAP to check whether a number is prime or not.
WAP  to print all prim numbr between 1 to 50.
WAP to print first 25 Fibonacci series.

0 Comments:

Post a Comment