```
import java.util.Scanner;
public class Main4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int a = s.nextInt();
String op = s.next();
int b = s.nextInt();
int result;
switch(op.charAt(0))
{
case '+':
result = a + b;
System.out.println(result);
break;
case '-':
result = a - b;
System.out.println(result);
break;
case '*':
result = a * b;
System.out.println(result);
break;
case '/':
result = a / b;
System.out.println(result);
break;
case '%':
result = a % b;
System.out.println(result);
break;
default:
System.out.println("입력 오류입니다!");
}
}
}
를 if문으로 바꾸었는데
import java.util.Scanner;
public class Main5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int a = s.nextInt();
String op = s.next();
int b = s.nextInt();
int result;
if (op == "+")
{
result = a + b;
System.out.println(result);
}
else if (op == "-")
{
result = a - b;
System.out.println(result);
}
else if (op == "*")
{
result = a * b;
System.out.println(result);
}
else if (op == "/")
{
result = a / b;
System.out.println(result);
}
else if (op == "%")
{
result = a % b;
System.out.println(result);
}
else
{
System.out.println("입력 오류입니다!");
}
}
}
```
를 실행했을 때 무조건 "입력 오류입니다!"만 떠서 어느 부분을 고쳐야하나요?
"+".equals(op)
"-".equals(op) 을 어떻게 넣어야 할지 모르겠습니다
sehongpark님의 답변
## 답변 코드
```
import java.util.Scanner;
public class Main4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int a = s.nextInt();
String op = s.next();
int b = s.nextInt();
int result;
if ("+".equals(op)) {
result = a + b;
System.out.println(result);
} else if ("-".equals(op)) {
result = a - b;
System.out.println(result);
} else if ("*".equals(op)) {
result = a * b;
System.out.println(result);
} else if ("/".equals(op)) {
result = a / b;
System.out.println(result);
} else if ("%".equals(op)) {
result = a % b;
System.out.println(result);
} else {
System.out.println("입력 오류입니다!");
}
}
}
```
jjm2947님의 답변
정말 쉬운 거였네요..
감사합니다!!