在下面的JAVA代碼Mul和Add運算符不工作只有X-y運算符結果我得到請請教如何找到這個問題的答案。請給出這個回答,如果循環只有x-y正在工作
public class oppswithvalue {
void calculate(int x,int y,String op)
{
//System.out.println(op);
if(op=="*")
System.out.println("X x Y : "+(x*y));
else if(op=="+")
System.out.println("X + Y : "+(x*y));
else
System.out.println("X - Y : "+(x-y));
}
public static void main(String args[]) throws IOException
{
BufferedReader ar=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter first number : ");
int no1=Integer.parseInt(ar.readLine());
System.out.println("Enter Second number : ");
int no2=Integer.parseInt(ar.readLine());
System.out.println("Enter an operator : ");
String op=ar.readLine();
oppswithvalue tt= new oppswithvalue();
tt.calculate(no1, no2,op);
}
}
的[我如何在Java中比較字符串?]可能重複(http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Kenster