【問題】Java簡單計算機


Recommended Posts

請問怎麼寫一個

在cmd.exe模式下執行java計算

的計算機程式

這是我寫到不會寫的程式碼

import java.lang.*;

class test {

public static void main(String[] args) {

long a = 0, b = 0 ;

double end =0;

char c = ' ';

a = Integer.parseInt(args[0]);

c = args[1];

b = Integer.parseInt(args[2]);

switch© {

case '+': end=a+b; break;

case '-': end=a-b; break;

case '*': end=a*b; break;

case '/': end=a/b; break;

case '^': end=Math.pow(a,b); break;

default: System.out.println("運算符號錯誤");

}

System.out.println(a+" "+c+" "+b+" = "+end);

}

}

因為老師教的ooxx

所以我不太懂宣告= ="

就是輸入

java test 數字 運算符號 數字

= ="

鏈接文章
分享到其他網站
  • 1 month later...
  • 1 month later...

import java.lang.*;

class test {

public static void main(String[] args) {

long a , b;

double end=0 ;

String c ;

a = Integer.parseInt(args[0]);

c = (args[1]);

b = Integer.parseInt(args[2]);

if(c.equals("+"))

end=a+b;

else if(c.equals("-"))

end=a-b;

else if(c.equals("*"))

end=a*b;

else if(c.equals("/"))

end=a/b;

else if(c.equals("^"))

end=Math.pow(a,b);

else System.out.println("運算符號錯誤");

System.out.println(a+" "+c+" "+b+" = "+end);

}

}

如上xd

鏈接文章
分享到其他網站

請登入後來留意見

在登入之後,您才能留意見



立即登入