0
我一直在做帕斯卡的三角形作业,我已经得到了用于按照我想要的方式打印三角形广告的整个代码。我们的老师要求我们在每一行上显示该行内数字乘法的结果;例如:在行1上它应该打印1,在第2行打印1,在第3行打印2,在第4行打印9等等...... 我已经写了一种类似的计数器阵列来做到这一点,但它不' t似乎工作,在这里我离开你我的代码,所以你可以检查出来,看看你能帮助我。顺便说一下,计数器数组是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();
}
}
}
你似乎是巴西人。试试http://pt.stackoverflow.com/ –