이것은 사용자가 지식을 테스트하기 위해 임의의 방정식을 제공하고 오류가 나타나지 않는 코드입니다. 코드를 실행하면 Eclipse에서 컴파일되지 않습니다. IntelliJ Idea에서 실행하면 실행되지만 코드가 나타나지 않으며 아무 것도 할 수 없습니다.내 자바 코드를 컴파일하는 방법은 무엇입니까?
package logical;
import java.util.Random;
import java.util.Scanner;
public class logical {
@SuppressWarnings("resource")
public static void main (String args[]){
int qn1, qn2; //Numbers for the question
int ua; //The users answer
int answer; //The actual answer
int counter = 0; //Controls the number of questions that can be answered
int tally = 0; //Number of correct responses
String again = "y";
Scanner in = new Scanner(System.in);
Random dice = new Random();
while(again == ("y") || again == ("Y")){
for(counter=1;counter>=5;counter++){
qn1 = 1+dice.nextInt(40);
qn2 = 1+dice.nextInt(40);
answer = qn1 + qn2;
System.out.printf("What is %d + %d",qn1,qn2);
ua = in.nextInt();
if(ua == answer){
System.out.println("That is correct!");
counter++;
tally++;
}
else{
System.out.println("Sorry, that is wrong! The correct answer is " + answer);
}
System.out.println("Would you like to try again?(Y/N)");
again = in.next();
if(again=="y" || again=="Y"){
counter=0;
}else {
System.out.println("Thanks for playing your results were " + tally + " out of 5");
}
}
}
System.out.println("Thanks for taking the math challenge!");
}
}
이며 컴파일 오류 메시지는 .....입니까? –
여기에 논리 오류가 있습니다'again == ("y")'=='사용하지 않고 equals() 메소드를 사용하여 문자열을 비교해야합니다 –
중괄호에있는 그 추한 주석을 제거하십시오. 나는 대학에서 무엇을 가르쳤는지 상관하지 않습니다. 그렇게하면 읽기가 더 어려워집니다. – byxor