私は宿題のためにパスカルの三角形をやっていて、三角形の広告を希望どおりに印刷するためのコード全体をすでに取得しています。私たちの先生は、すべての行に、その行内の数値の乗算の結果を表示するように求めました。たとえば、行 1 では 1 を出力し、行 2 では 1 を出力し、行 3 では 2 を出力し、行 4 では 9 を出力します。動作するようです。ここに私のコードを残しておきますので、チェックアウトして、私を助けることができるかどうかを確認してください。ちなみにカウンター配列はc[]です。どうもありがとうございました!
import javax.swing.*;
import java.util.*;
public class class1_080414_Rodrigo {
public static void main(String[] args) {
// TODO Auto-generated method stub
String fila;
int f, a=0, b=0;
//
fila=JOptionPane.showInputDialog(null, "Until which line of the triangle would you like to prnt?");
f=Integer.parseInt(fila);
//
if (f<0){
JOptionPane.showMessageDialog (null, "You cannot type negative numbers.");
}
int triangulo [][] = new int[f][f];
int c [] = new int [f];
//
for (a=0;a<f;a++){
for (b=0; b<f; b++){
triangulo[a][b] = 0;
}
}
for (a=0;a<f;a++){
triangulo[a][0] = 1;
}
for (a=1;a<f;a++) {
for (b=1;b<f;b++) {
triangulo[a][b] = triangulo[a-1][b-1] + triangulo[a-1][b];
}
}
for (a=0;a<f;a++) {
for(b=0;b<=a;b++) {
if (b==0){
System.out.format("%"+(80-a)+"s", "");
}
c[a]=1;
c[a]=c[a]*triangulo[a][b];
System.out.print(triangulo[a][b]+" ");
}
System.out.print(" ="+c[a]);
System.out.println();
}
}
}