【发布时间】:2015-04-16 15:06:06
【问题描述】:
我有我在 create() 方法中创建的对象编号列表,我想访问它以便可以在 question() 方法中使用它。
还有其他我可能错过的方法吗?我在搞砸什么吗?如果没有,我该怎么做才能获得与以下相同的功能?
private static void create() {
Scanner input = new Scanner(System.in);
int length,offset;
System.out.print("Input the size of the numbers : ");
length = input.nextInt();
System.out.print("Input the Offset : ");
offset = input.nextInt();
NumberList numberlist= new NumberList(length, offset);
}
private static void question(){
Scanner input = new Scanner(System.in);
System.out.print("Please enter a command or type ?: ");
String c = input.nextLine();
if (c.equals("a")){
create();
}else if(c.equals("b")){
numberlist.flip(); \\ error
}else if(c.equals("c")){
numberlist.shuffle(); \\ error
}else if(c.equals("d")){
numberlist.printInfo(); \\ error
}
}
【问题讨论】:
-
将其声明为字段,而不是您方法中的局部变量。
标签: java