System.out.print("請輸入:例如1+2,4/6 ... ");
Scanner s =新掃描儀(system . in);
string str = s . next();
if(str.length()==3){
嘗試{
float a = float . parse float(str . substring(0,1));
float b = float . parse float(str . substring(2,3));
String c = str.substring(1,2);
switch (c.hashCode()) {
案例43:
system . out . println(a+"+"+b+" = "+(a+b));
打破;
案例45:
system . out . println(a+"+"+b+" = "+(a-b));
打破;
案例42:
system . out . println(a+"+"+b+" = "+(a * b));
打破;
案例47:
system . out . println(a+"+"+b+" = "+(a/b));
打破;
默認值:
打破;
}
} catch(異常e) {
System.out.println("輸入錯誤");
}
}否則{
System.out.println("輸入錯誤");
}
}
給它壹個好的評價!謝謝妳