Eclipse写Java的时候出现Exception in thread "main" java.lang.Error: Unresolved compilation problem:
代码是这样的,检查了但是看不出来怎么回事packageJava3;importjava.util.*;publicclassJava3{publicstaticvoidm...
代码是这样的,检查了但是看不出来怎么回事
package Java3;
import java.util.*;
public class Java3 {
public static void main(String[] args) {
System.out.println("Input n:");
Scanner input = new Scanner(System.in);
int n = Integer.parseInt(input.next());
int i;
i = n * n;
int[] a;
queen(i,a);
for(int k = 0;k < a.length;k++)
System.out.println(a[k]);
}
}
public static void queen(int m,int[] list) {
int[] list = new int [m];
for(int i = 0,j = 0;i < list.length;i++,j++) {
list[j] = i + 1;
}
} 展开
package Java3;
import java.util.*;
public class Java3 {
public static void main(String[] args) {
System.out.println("Input n:");
Scanner input = new Scanner(System.in);
int n = Integer.parseInt(input.next());
int i;
i = n * n;
int[] a;
queen(i,a);
for(int k = 0;k < a.length;k++)
System.out.println(a[k]);
}
}
public static void queen(int m,int[] list) {
int[] list = new int [m];
for(int i = 0,j = 0;i < list.length;i++,j++) {
list[j] = i + 1;
}
} 展开
1个回答
展开全部
import java.util.*;
public class Java3 {
public static void main(String[] args) {
System.out.println("Input n:");
Scanner input = new Scanner(System.in);
int n = Integer.parseInt(input.next());
int i;
i = n * n;
int[] a = new int[2]; //错误1:int 数组a未初始化
queen(i, a);
for (int k = 0; k < a.length; k++)
System.out.println(a[k]);
}
// 错误2: queen 的static 方法,应该放在 class Java3 内部
public static void queen(int m,int[] list) {
int[] list = new int [m]; //错误地方3:list 变量已经存在,重名了
for(int i = 0,j = 0;i < list.length;i++,j++) {
list[j] = i + 1;
}
}
}
希望对你有帮助,如果满意还望采纳!^_^
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询