Hi,
will ein Pascalsches Dreieck ausgeben:
Hier der Code
Aber leider gibt er mir folgende Fehlermeldung
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Pascal.main(Pascal.java:28)
aus.
Was mache ich falsch?
will ein Pascalsches Dreieck ausgeben:
Hier der Code
Java:
public class Pascal {
public static void printPascal (int lines) {
int[][] array = new int [lines][lines];
for (int i=0; i< lines; i++) {
for (int j=0; j <=i; j++) {
if (j == 0 || j == i) {
array[i][j] = 1;
}
else {
array[i][j] = array[i-1][j-1] + array[i-1][j];
}
}
}
for (int i=0; i<lines; i++) {
for (int j=0; j<=i; j++) {
System.out.print (array[i][j] + " ");
}
System.out.println();
}
}
public static void main (String[] args){
printPascal (Integer.parseInt (args[0]));
}
}
Aber leider gibt er mir folgende Fehlermeldung
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Pascal.main(Pascal.java:28)
aus.
Was mache ich falsch?