Java classic algorithm _ 028 print Yang Hui triangle

Source: Internet
Author: User
Package WZS. arithmetics; // question: print out the Yang Hui triangle (10 rows are required, as shown in) // 1 // 1 1 // 1 2 1 // 1 3 3 1 // 1 4 6 4 1 // 1 5 10 5 1 public class test_wzs28 {public static void main (string [] ARGs) {int line = 10; // print the number of rows int [] [] arr = new int [Line] [line]; // control the row for (INT I = 0; I <line; I ++) {// control column for (Int J = 0; j <I + 1; j ++) {if (I = 0 | j = 0 | I = J) {arr [I] [J] = 1 ;} else {arr [I] [J] = arr [I-1] [J-1] + arr [I-1] [J];} system. out. print (ARR [I] [J] + "\ t");} system. out. println ();}}}

Output result:

11112113311464115101051161520156117213535217118285670562881193684126126843691

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.