日期:2014-05-20 浏览次数:20777 次
public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.println("请输入分数1:"); float scor1 = sc.nextFloat(); System.out.println("请输运算符号"); String str = sc.next(); System.out.println("请输入分数2:"); float scor2 = sc.nextFloat(); System.out.println("结果是: " + util(scor1, str, scor2)); } public static float util(float scor1, String str, float scor2) { float rs = 0; if (str.equalsIgnoreCase("+")) { rs = scor1 + scor2; } else if (str.equalsIgnoreCase("-")) { rs = scor1 - scor2; } else if (str.equalsIgnoreCase("*")) { rs = scor1 * scor2; } else if (str.equalsIgnoreCase("/")) { rs = scor1 / scor2; } else { return 0; } return rs; } }