这可能是一个愚蠢的问题,但
我有这个代码
public class Main {
public static int choice;
public static void main(String[] args) throws InterruptedException {
...
//Get Input
Scanner reader = new Scanner(System.in);
System.out.println("");
System.out.print("Choose The Number!");
int choice = reader.nextInt();
我有另一个类,想要与int进行交互,选择
public class DevSetting {
public static void main(String[] args) {
// TODO Auto-generated method stub
if( Main.choice == 4 ){
System.out.print("Testing");
}
}
}
但是当我输入'4'程序终止时,但我认为它可能不是实际代码,它可能是我如何设置项目。
无论如何谢谢!
答案 0 :(得分:2)
最好是在第二个类中创建一个公共方法,比如
DevSetting.doSomething(choice);
然后第一个类可以通过以下方法调用此方法:
{{1}}
将更改的选择信息传递给此方法。