1
我想要做的是,我有2場比賽,一場叫做ToF,一場叫做旋轉。 如果輸入的字符串是「旋轉」,則啓動旋轉游戲。並將控制檯輸入轉換爲int。錯誤:不兼容的類型簡單的遊戲選擇與掃描儀?
如果輸入int爲1,則旋轉車輪。 如果輸入的int爲-1,則將控制檯輸入更改爲String,並退出循環。
但我收到此錯誤:
src\Main.java:39: error: incompatible types
input = console.nextLine();
我的屬性:
private static Scanner console = new Scanner(System.in);
private static Spin spin = new Spin();
private static String input = "";
private static String[] gamesArray = new String[] {"spin", "tof"};
private static boolean spinWheel = false;
private static boolean tof = false;
而且有錯誤:
有什麼不對?它爲什麼這樣做?我怎樣才能解決這個問題?
'Scanner#nextLine()'返回一個字符串。你將它分配給一個'int'。你應該使用'Scanner#hasNextInt()'與'Scanner#nextInt()'結合使用。 –