我在下面构造客户端类,我只是想知道飞机是否等于或=(2-D阵列,2-D阵列),我如何在陈述中添加第二个阵列Airplane steveo = new Airplane (2-D阵列,2-D阵列)。
public class AirplaneClient
{
public static void main(String [] args)
{
Airplane steveo = new Airplane({"o ", "o ", "o ","o "}
{"o ", "o ", "o ","o "}
{"o ", "o ", "o ","o "}
{"o ", "o ", "o ","o "}
{"o ", "o ", "o ","o "}
);
}
}
如果您仍然对我的问题提出的疑问感到困惑,那么我基本上是在尝试以下代码:
public class AirplaneClient
{
public static void main(String [] args)
{
Airplane steveo = new Airplane(2-D Array, 2-D Array);
}
}
我对它的语法有一个想法:
public class AirplaneClient
{
public static void main(String [] args)
{
Airplane steveo = new Airplane({"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "}
{"o ", "o ", "o ", "o "});
}
}
但是,我对此并不乐观。请帮忙!
PS:
如果这也有帮助,请使用以下飞机的构造函数:
import java.util.*;
public class Airplane
{
private String[][] first;
private String[][] economy;
public Airplane()
{
first = new String[5][4];
economy = new String[30][6];
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 4; ++j)
{
first[i][j] = "o ";
}
}
for (int i = 0; i < 30; i++)
{
for(int j = 0; j < 6; j++)
{
economy[i][j] = "o ";
}
}
}
public Airplane(String[][] first1, String[][] economy1)
{
first = first1;
economy = economy1;
}
最佳答案
首先将您的构造函数输入更改为:
public Airplane(String[][] first1, String[][] economy1) {
first = first1;
economy = economy1;
}
然后像这样调用它:
Airplane steveo = new Airplane(
new String[][] {
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "}
}
,
new String[][] {
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "},
{"o ", "o ", "o ", "o "}
});
关于java - 如何在客户端类中制作(2-D数组,2-D数组),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42496404/