Tuesday, 10 May 2011


(BlueJ) Java Program to display Triangle : BREAK DEMO.

Code:
/* Display Triangle as follow : BREAK DEMO.
    1
    2 3
    4 5 6
    7 8 9 10 ... N */
class Output1{
      public static void main(int n){
          int c=0;
          
         loop1: for(int i=1;i<=n;i++){
         loop2: for(int j=1;j<=i;j++){
                       if(c!=n){
                            c++;
                            System.out.print(c+" ");
                       }
                       else
                           break loop1;
                    }
                    System.out.print("\n");
                 }
     }
}

Comment below for your Query and Feedback... :)

Related Posts :



1 comment:

  1. there is no main method in the above program it showing error

    ReplyDelete