간단한 계산기를 만들고 사용자가 "오류"를 표시하려고 할 때 제목에 오류가 계속 나타나려고합니다. 주어진 조작 유형 중 하나에 들어 가지 않습니다.Java- 구문 토큰 오류 "! =",이 토큰 다음에 예상되는 이름
import java.util.Scanner;
public class experiments {
public static void main(String args[]) {
Scanner userInput = new Scanner(System.in);
String operation;
double fNum, sNum, ans;
//select type of operation
System.out.println("Type addition, subtraction, multiplication, or division, then press enter");
operation = userInput.nextLine();
if (operation!=("addition","subtraction","multiplication","division")) {
System.out.println("error");
}
//enter numbers
System.out.println("Enter first number");
fNum = userInput.nextDouble();
System.out.println("Enter second number");
sNum = userInput.nextDouble();
//calculate
if (operation.equals("addition")) {
ans=fNum + sNum;
}
else if (operation.equals("subtraction")) {
ans=fNum - sNum;
}
else if (operation.equals("multiplication")){
ans=fNum * sNum;
}
else if (operation.equals("division")) {
ans=fNum/sNum;
}
//print answer
System.out.println("The answer is ");
System.out.println(ans);
}
}
난 당신이'싶은 생각 확인하기 위해 이것을 사용 && ', 처음 두 달리 한 것은 사실로 보장된다. – Kevin
두 배 음원 사랑 : P – MadProgrammer
@Kevin 방금 한 개로 감쌀 수있었습니다! (...) block : P – MadProgrammer