public static void main(String [] args)
{
//初始化数组
double[][] results = new double[7][6];
//附加原始方法
Catapult[][] data = new Catapult[7][6];
//打印标题
printHeading();
// For-loop将数据输入原始方法
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j < 6; j++)
{
data[i][j] = new Catapult((double) (i + 5) * 5.0, (double) (j + 4) * 5.0);
data[i][j].convertDegreesToRadians();
data[i][j].convertMPHToMetersPerSec();
System.out.println();
System.out.println(data[i][0] + "" + data[i][j] + "" + data[i][j+1] + "" + data[i][j+2] + data[i][j+3] + " " + data[i][j+4] + " " + data[i][j+5]);
}
}
每当我尝试打印时,值都为null。如何在2d数组中正确打印i和j的值?
答案 0 :(得分:1)
这样的东西?
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j < 6; j++)
{
data[i][j] = new Catapult((double) (i + 5) * 5.0, (double) (j + 4) * 5.0);
data[i][j].convertDegreesToRadians();
data[i][j].convertMPHToMetersPerSec();
System.out.print(data[i][j] + " ");
}
System.out.println();
}
希望有所帮助