rss
Twitter Delicious Facebook Digg Stumbleupon Favorites
Showing posts with label traingle. Show all posts
Showing posts with label traingle. Show all posts

Saturday, October 8, 2011

A program to display Inverted Triangle.

Display :
                5 5 5 5 5
          4 4 4 4
          3 3 3
          2 2
          1

class CreateInvertTriangle{
      public static void main(String args[]){
           int num = Integer.parseInt(args[0]);
           while(num > 0){
              for(int j=1;j<=num;j++){
                  System.out.print(" "+num+" ");
                }
                System.out.print("\n");
                num--;
            }
      }
}

A program to generate a Triangle.

Display :

               1
              2 2
              3 3 3
              4 4 4 4
class CreateTriangle{
      public static void main(String args[]){
          int num = Integer.parseInt(args[0]);
          for(int i=1;i<=num;i++){
             for(int j=1;j<=i;j++){
                System.out.print(" "+i+" ");
             }
             System.out.print("\n");
           } 
    }
}
Powered by Blogger.