이것은 내 코드입니다. 나는 같은 것을 지키기 위해 wordOfTheDay와 대답이 필요합니다. "오늘의 단어는 무엇입니까?"와 "3 * 8의 답은 무엇입니까?"라는 대답을 입력해야하며 답변에 따라 정답으로 받아 들여지거나 거부되며 다시 시도됩니다. 나는이 컴파일러 오류를클래스 상수 최종 변수
오류가 계속 : 최종 변수 wordOfTheDay 오류에 값을 할당 할 수 없습니다 : 이미 wordOfTheDay
을 설정 한
//The word of the day is Kitten
import java.util.Scanner;
public class SchmeisserKLE41 {
public static final Scanner input = new Scanner(System.in);
public static final String wordOfTheDay = "Kitten";
public static final int answer = 24;
public static void main(String[] args) {
int attempts = 3;
System.out.printf("Please enter the word of the day:");
wordOfTheDay = input.nextLine();
do{
-- attempts;
if(attempts == 0){
System.out.printf("Sorry! You've exhausted all your attempts!");
break;
}
System.out.printf("Invalid! Try again %d attempt(s) left.", attempts);
wordOfTheDay = input.nextLine();
}
while(!wordOfTheDay.equals("Kitten"));
System.out.printf("\nWhat is the answer to 3 * 8?");
answer = input.nextInt();
System.exit(0);
}
}
wordOfTheDay를 "새끼 고양이"로 유지하고 올바르게 수정되었는지 테스트 할 수 있습니까? –