Java Beginner (iv)

Source: Internet
Author: User

Diagram of two-dimensional array

Second, plot dynamic creation of two-dimensional arrays

Three, Yang Hui triangle exercises:

1 ImportJava.util.Scanner;2 classarray2demo{3     //Realizing the Yang Hui Triangle4      Public Static voidMain (string[] args) {5         //Creating a Keyboard entry object6Scanner sc=NewScanner (system.in);7System.out.println ("Please enter data:");8         intn=sc.nextint ();9         Ten         //defining a two-dimensional array One         int[] arr=New int[n][n]; A         //assign a value of 1 to the first and last column of each row of this two-dimensional array -          for(intx=0;x<arr.length;x++){ -Arr[x][0]=1;//first column per row theArr[x][x]=1;//last column of each row -         } -         //rule: Starting with the third row, the value of each element is the sum of the previous column and the value of the column in the previous row -          for(intx=2;x<arr.length;x++){ +             //because the first and last columns in each row are assigned a value of 1, you should traverse the column by 1 minus -              for(inty=1;y<=x-1;y++){ +                 //Assign values by law AArr[x][y]=arr[x-1][y-1]+arr[x-1][y]; at             } -         } -         //Print Output -          for(inti=0;i<arr.length;i++){ -              for(intj=0;j<=i;j++){ - System.out.print (Arr[i][j]); in             } - System.out.println (); to         } +     } -}

Java Beginner (iv)

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.