我知道這是非常基本的Java,但我正在嘗試學習。有人能幫我理解我的錯誤,我該怎麼做來解決它?Java - 將用戶輸入分配給變量並顯示Scoreboard
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int teamA = 0;
int teamB = 0;
//asks for the team selection
System.out.println("Would you like to be in Team A or Tema B? Write A for team A and B for team B");
Scanner input = new Scanner(System.in);
int result = input.nextInt();
public String scoreBoard() {
String displayScoreBoard = "No Score";
if (result.toString == "A" || result.toString == "a"){
teamA++;
displayScoreBoard = "Score of TeamX is" + teamA;
} else if (result.toString == "B" || result.toString == "b"){
teamB++;
displayScoreBoard = "Score of TeamY is" + teamB;
} System.out.println(displayScoreBoard.toString);
}
// write your code here
}
}
不要把'Strings'與'=='用'equals'代替,或者在這種情況下'equalsIgnoreCase'。你的'result.toString()'也不能是「A」或「B」,因爲你期望一個整數。 – Eclipse
非常感謝您的幫助。它解決了我的問題。 :-) –