请问这段java错在那里

来源:百度知道 编辑:UC知道 时间:2024/06/05 17:53:28
public class hello {
public static void main (String[] args)
{
int [][] x;
x=new int (x[2][2]);
x[0][0]=11;
x[1][1]=22;
x[2][2]=33;
System.out.println(x[0][0]);
System.out.println(x[1][1]);
System.out.println(x[1][2]);
System.out.println(x[2][2]);
}
}
D:\class\1>javac hello.java
hello.java:16: 需要 '['
x=new int (x[2][2]);
^
hello.java:16: 需要 ']'
x=new int (x[2][2]);
^
2 错误

D:\class\1>javac hello.java
hello.java:16: 需要 '['
x=new int x[2][2];
^
hello.java:16: 需要 ']'
x=new int x[2][2];
^
2 错误

你的12没有值,好像定义也有点错

语法错误,应该这样写
int [][] x;
x=new int[2][2] ;
越界x[2][2]=33;
横纵坐标的范围只能是0,1

public class hello {
public static void main (String[] args)
{
int [][] x;
x=new int x[2][2]; //括号去了
x[0][0]=11;
x[1][1]=22;
//x[2][2]=33; 越界
System.out.println(x[0][0]);
System.out.println(x[1][1]);
System.out.println(x[1][2]);
//System.out.println(x[2][2]); 越界
}
}