大话设计模式
1.1面试受挫里面的样例,自己是个小菜,自学java中,写的代码有问题,请指导一下,让我更加进步,上代码。
package btdp.one.one;
import java.util.Scanner;
/**
* Big talk design pattern 1.1
* desc: Simple calculator
* @date 2018-08-14
* @author szq
*
*/
public class Program1 {
public static void main(String[] args) {
//double A,C,D char B这样命名是非常不规范的
System.out.println("请输入数字A:");
Scanner scan = new Scanner(System.in);
double A = scan.nextDouble();
System.out.println("请输入数字B:(+、-、*、/)");
Scanner scan1 = new Scanner(System.in);
char B = scan1.next().charAt(0);
System.out.println("请输入数字C:");
Scanner scan2 = new Scanner(System.in);
double C = scan2.nextDouble();
double D = 0L;
//判断分支,这样写法,意味着每个条件都要做判断,等于计算机做了三次无用功
if (B == '+')
D = A + C;
if (B == '-') {
D = A - C;
}
if (B == '*')
D = A * C;
if (B == '/')
D = A / C; //如果除数时,输入0,字符怎么办
System.out.println(D);
}
}