GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JavaLearningPath/Basic/src/array/YanghuiTest.java at master · AlexGithubbb/JavaLearningPath Expand file tree/ Copy pathYanghuiTest.javaMore file actions 35 lines (25 loc) · 957 Bytes / Copy pathYanghuiTest.javaFile metadata and controls35 lines (25 loc) · 957 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package array; // YangHui triangle public class YanghuiTest { public static void main(String[] args) { // initialize 2 dimension array int[][] yanghui = new int[10][]; // assign value to it for (int i = 0; i < yanghui.length; i++) { yanghui[i] = new int[i+1]; // assign 1 to the first and last one yanghui[i][0] = yanghui[i][i] = 1; for (int j = 1; j < yanghui[i].length -1; j++) { // the yanghui rules, value of target item equals to the above one + the one on the left of the above one yanghui[i][j] = yanghui[i-1][j] + yanghui[i-1][j-1]; } } // iterate yanghui triangle for (int i = 0; i < yanghui.length; i++) { for (int j = 0; j < yanghui[i].length; j++) { System.out.print(yanghui[i][j] + " "); } System.out.println(); } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |