简单的计算器
2016-07-11 本文已影响0人
虾米_小峰
package com.SC;
import java.util.Scanner;
public class operate {
/**
* 做一个简单的计算器
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double sum = 0;//初始化sum值
System.out.println("请输入第一个数:");
double num1 = sc.nextDouble();
System.out.println("请输入运算符(+,-,*,%,/):");
String operat = sc.next();
System.out.println("请输入第二个数:");
double num2 = sc.nextDouble();
if(operat.equals("+")){
sum = num1+num2;
}else if(operat.equals("-")){
sum = num1-num2;
}else if(operat.equals("*")){
sum = num1*num2;
}else if(operat.equals("%")){
sum = num1%num2;
}else if(operat.equals("/")){
sum = num1/num2;
}
System.out.println(sum);
}
}