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/ –