Java 在数组中声明数组
我刚刚开始了一个Java编程类,在数组中设置数组时遇到了问题 例如:Java 在数组中声明数组,java,Java,我刚刚开始了一个Java编程类,在数组中设置数组时遇到了问题 例如: public class ABLoop { int x; ABLoop[]Loop = new ABLoop[x]; int[]numb; public void fortime(int number){ x=number; for(int multiplier = 0; multiplier <= x; multiplier++){
public class ABLoop {
int x;
ABLoop[]Loop = new ABLoop[x];
int[]numb;
public void fortime(int number){
x=number;
for(int multiplier = 0; multiplier <= x; multiplier++){
Loop[multiplier]= new Loop[multiplier+1];
公共类ABLoop{
int x;
ABLoop[]循环=新的ABLoop[x];
int[]麻木;
公共无效时间(整数){
x=数量;
对于(int-multiplier=0;multiplier,这个类将编译并运行,但我不知道您在这里做什么
public class ABLoop {
int x;
ABLoop[] loop;
int [] numb;
public ABLoop(int value) {
if (value < 0)
throw new IllegalArgumentException("value cannot be negative");
this.x = value;
this.loop = new ABLoop[this.x];
this.numb = new int[this.x]; // no idea what you're doing here; just guessing
}
public void fortime() {
for (int i = 0; i < this.x; ++i) {
this.loop[i] = new ABLoop(i); // What are you doing? Just guessing.
}
}
}
公共类ABLoop{
int x;
ABLoop[]循环;
int[]麻木;
公共ABLoop(int值){
如果(值<0)
抛出新的IllegalArgumentException(“值不能为负”);
这个.x=值;
this.loop=new ABLoop[this.x];
this.numb=newint[this.x];//不知道你在这里做什么;只是猜测而已
}
公共时间(){
对于(int i=0;i
我不知道这是否仍然相关,但最后一行:
Loop[multiplier]= new Loop[multiplier+1];
应该是
Loop[multiplier]= new ABLoop[multiplier+1];
Loop
是一个变量,ABLoop
是一个类型;new
需要一个类型。想象一下
int[] a;
a = new a[7];
或
这段代码几乎在每一个方面都被完全破坏了;很难知道从哪里开始。请更清楚地解释您正在尝试做什么。您是否正在尝试增加内部阵列的容量并维护现有阵列元素?
int[] a;
a = new int[7];