Java-Yang Hui Triangle

Source: Internet
Author: User

1  Public Static voidMain (string[] args) {2         intTriangle[][] =New int[10] [];//creating a two-dimensional array3         //traversing the first layer of a two-dimensional array4          for(inti = 0; i < triangle.length; i++) {5Triangle[i] =New int[i + 1];//Initialize the size of the second-level array6             //traversing a second-level array7              for(intj = 0; J <= I; J + +) {8                 //assigns an array element on both sides to a value of 19                 if(j = = 0 | | j = =i) {TenTRIANGLE[I][J] = 1; One}Else{//other values are calculated by formula ATRIANGLE[I][J] = triangle[i-1][j] -+ triangle[i-1][j-1]; -                 } theSystem.out.print (Triangle[i][j] + "\ t");//Output array elements -             } -System.out.println ();//line Break -         } +}

Output Result:

1
11
121
1331
14641
15101051
1615201561
172135352171
18285670562881
193684126126843691

Java-Yang Hui Triangle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.