我想调用这个方法从用户输入中输入一个坐标点。如何调用一个不返回任何东西的方法?
public class Cases {
public static Result Case1(){
Scanner in = new Scanner(System.in);
System.out.println("Enter index: ");
int i = in.nextInt(); //validate
System.out.print("Enter integers x, y to replace: ");
int x = in.nextInt();
int y = in.nextInt();
A[i] = new Point(x, y);
if(occupancy<i)
occupancy=i;
}
}
,但我不知道如何使它工作,因为它并不需要一个return语句。
这是我如何把它称为从我的主要方法:
Result r = null;
r = Cases.Case1();
我想我所有的情况下,从switch语句到这个单独的方法,但我不能,甚至让他们的一个工作。我错过了什么?
编辑:对不起,我认为你*做*需要在这里返回声明,这可能是问题。 (是的,我的编译器说“缺少return语句”。另外A和占用是未定义的。) – markspace
'Cases.Case1()'返回一个'Result'对象。它不会那样编译。您应该将返回类型更改为void,并改变您称之为的方式(您不必将其分配给引用变量)。 –