Create a simple calculator, it is important to understand its logic
Simple calculator main arithmetic calculation is, in the calculation of particular note that the division, the denominator is not 0, then need determination.
Investigation point: arithmetic operators, judgment statement
production process:
1. At least two digital calculator, so the definition of a, b
double a = 10.4;
double b = 0;
2. Set c is the operator "/"
String c = "/";
3. There are four kinds of arithmetic operations, as follows
if (c.equals("+")){
result = a + b;
System.out.println("加法的结果====>"+result);
}else if (c.equals("-")){
result = a - b;
System.out.println("减法的结果====>"+result);
}else if (c.equals("*")){
result = a * b;
System.out.println("乘法法的结果====>"+result);
}else if (c.equals("/")){
//判断参数运算是否含有0
// || 或运算符
if (b==0){
System.out.println("分母不能为0");
}else {
result = a / b;
System.out.println("除法的结果====>"+result);
}
}else {
System.out.println("超出算术运算符范围");
}
Note that division, the denominator is 0 or not 0, the determination