我才開始學習計算機的基礎課程,還沒學到java,老師要我們自己先開始預習java,就給我們出了個題目就是做個可以加減乘除的電腦,我寫個代碼,但是又點問題,希望大家能幫幫小弟這個忙,在這裡不勝感激!~
謝謝哥哥姐姐!~
import java.util.*;
public class ty{
public static void main(String[] args)
{
int a,b;
String c;
Scanner s =new Scanner(System.in);
System.out.println("輸入計算的第1個數:");
a = s.nextInt();
System.out.println("輸入計算的第2個數:");
b = s.nextInt();
System.out.println("輸入計算方法(加、減、乘、除):");
c = s.nextLine();
if(c=="+")
{
System.out.println("和"+"為:"+(a+b));
}
if(c=="-")
{
System.out.println("減"+"為:"+(a-b));
}
if(c=="*")
{
System.out.println("乘"+"為:"+(a*b));
}
if(c=="/")
{
System.out.println("除"+"為"+(a/b));
}
}
}