Java algorithms: print Pascal's Triangle

Package Test; 
 
/ ** 
 * Title: Triangle print out (printed out in claim 10 below the line) 
 * 
 . 1 
 . 1. 1 
 . 1 2. 1 
 . 1. 3. 3. 1 
 . 1. 4. 6. 4. 1 
 . 1. 5. 1. 5 10 10 
 * / 
public  class YHSanJiao {
     public  static  void main (String [] args) {
         int [] [] = ARR new new  int [. 6] [. 6 ];
         // generating vertical and diagonal 
        for ( int I = 0; I <. 6; I ++ ) { 
            ARR [I] [I] =. 1 ; 
            ARR [I] [ 0] =. 1 ; 
        } 
        //Generated according to the element head elements and the head of the left side of the element 
        for ( int I = 2; I <. 6; I ++ ) {
             for ( int J =. 1; J <= I-. 1; J ++ ) { 
                ARR [I] [ J] = ARR [I-. 1] [J] + ARR [I-. 1] [J-. 1 ]; 
            } 
        } 
        // printouts 
        for ( int I = 0; I <. 6; I ++ ) {
             for ( int J 0 =; J <= I; J ++ ) { 
                of System.out.print (ARR [I] [J] + "" ); 
            } 
            System.out.println (); 
        } 
    } 
}

From the micro-channel public number: Programming Society

Advanced programmers daily book, please pay attention!

 

Guess you like

Origin www.cnblogs.com/ai10999/p/11448720.html