我只是一个新手,当谈到编程和学生。我的任务是创建一个乘法表的二维数组,但我似乎得到相同的错误超时:java.lang.arrayindexoutofboundsexception 10需要帮助代码不工作
请帮助。
继承人的代码:
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);
}
}
}
}
干杯,
我
谢谢!
如何C++与你的问题? –
提示:所有声明* ROWS和COLUMNS的* local *变量的循环都很糟糕,IMO。 'COLUMNS
您是否尝试过调试以查看发生了什么? – n247s