実験課題3

Exercise 3(課題3) See the section 3.2.1. "Stepwise program decomposition". Show the source code to display Pascal's triangle with the height given \(h\) as the following figures and its execution result as a screenshot. Pascal's triangle is a numbers array arranged in triangle. This arrangement manner is that its top line is only 1, and each number after top line is plus left above number and right above number (if left or right above number is not in, then it number is 0). Follow the instructions below to run program.

  1. create the Java application project named chapter3kadai3.
  2. create main method to run the program in the project class.
  3. create the program to display Pascal's triangle such by using double for loop such as below figure in main method.
  4. take the screenshot of the execution result.
1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 
1 5 10 10 5 1 
1 6 15 20 15 6 1 
Figure:Display example of Pascal's triangle with h=7

The simplest way to implement the calculation of Pascal's triangle is to fill 2d array object as follows:

int[][] triangle = new int[h][h];  // 二次元配列オブジェクトをtriangleに作成。ここでhはScannerで読み取った数。

// for文を使って最上段から順に埋めていく。
for (int j = 0; j < h; j++) {
	for(int i = 0; i <= j; i++) {
/* 以下略 */
Figure:Creation of Pascal's triangle by using 2d array object

(3.2.1.節をよく読み、chapter3kadai3プロジェクトを作成し、段階的作成法を用いて、与えられたhの高さのパスカルの三角形を表示するプログラムを作成しなさい。このとき作用はメソッドとして分割すること。それに伴い、作用をどのように分解したかもまとめなさい。そして、プログラムのソースコード、および実行結果のスクリーンショットを報告しなさい。パスカルの三角形とは、最上段が1で、それより下の段はその位置の右上の数と左上の数(存在しなければ0)の和を配置することで作られる三角形状である。)