重複の可能性:
Java で文字列を比較するにはどうすればよいですか?
プログラムで、割り当てられた文字列演算子を使用して 2 つの整数を計算できないのはなぜですか? 何らかの理由で、プログラムがユーザーからの入力を受け入れていないようです。
import java.io.*;
public class IntCalc {
public static void main (String [] args) throws IOException {
BufferedReader kb = new BufferedReader (new InputStreamReader (System.in));
System.out.println ("This program performs an integer calculation of your choice.");
System.out.println ("Enter an integer: ");
int x = Integer.parseInt (kb.readLine());
System.out.println ("Enter a second integer: ");
int y = Integer.parseInt (kb.readLine());
System.out.print ("Would you like to find the sum, difference, product, quotient, or remainder of your product?: ");
String operator = kb.readLine();
int finalNum;
if (operator == "sum") {
int finalNum = (x + y);
} else if (operator == "difference") {
int finalNum = (x - y);
} else if (operator == "product") {
int finalNum = (x * y);
} else if (operator == "remainder") {
int finalNum = (x % y);
}
System.out.print ("The " + operator + " of your two integers is " + finalNum ".");
}
}