Ich bin nur ein Anfänger, wenn es um die Programmierung geht, und ein Student. Ich wurde beauftragt, ein 2-D-Array einer Multiplikationstabelle zu erstellen, aber ich scheine, um den gleichen Fehler evertime zu bekommen: java.lang.arrayindexoutofboundexception 10Brauchen Sie Hilfe Code funktioniert nicht
Pls Hilfe.
Heres der Code:
public class MulTtable {
// rows and columns are declared as constants
static final int ROWS= 10;
static final int COLUMNS= 10;
// prints the content of the 2-D array
public static void printTable(char mt[][]){
int n=ROWS;
for (int row = 0; row < ROWS; row++){
for (int COLUMNS = 0; COLUMNS < COLUMNS; COLUMNS++){
{
System.out.print(mt[ROWS][COLUMNS] + "\t");
}
System.out.println();
}
}
}
public static void main(String[] args){
int mTable[][]= new int[ROWS][COLUMNS];
for (int ROWS = 0; ROWS < mTable.length; ROWS++){
for (int COLUMNS = 0; ROWS < mTable[ROWS].length; COLUMNS++){
if (ROWS<11) // stores integer 1+1 in the first row of the array
mTable[ROWS][COLUMNS] = 1+1;
else
mTable[ROWS][COLUMNS] = (ROWS)* (COLUMNS);
}
}
}
}
Cheers,
Me
Thank you!
Wie wird C++ zu Ihrer Frage? –
Hinweis: alle Ihre Schleifen, die * lokale * Variablen namens "ROWS" und "COLUMNS" deklarieren, sind ziemlich pleite, IMO. Die Schleifenbedingung von 'COLUMNS
Haben Sie versucht, es zu debuggen, um zu sehen, was passiert? – n247s