PHPstorm汉化

天猫商城如何创建店铺宝营销活动?

  返回  

大话设计模式 Java 代码1

2021/8/20 21:48:54 浏览:

1.8 业务的封装

import java.util.*;

public class design {

	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in); //若使用Console, 出错
			System.out.println("请输入数字A");
			String A = sc.nextLine();
			System.out.println("请选择运算符号(+、-、*、/):");
			String B = sc.nextLine();
			System.out.println("请输入数字B:");
			String C = sc.nextLine();
			double c = Double.parseDouble(C);
			
			if (B.equals("/") && c == 0) 
				throw new ArithmeticException();
			
			double ans = clclt(Double.parseDouble(A), B, c);
			System.out.println("The answer is " + ans);
			
			}catch (ArithmeticException e) {
				System.out.println("您的输入有误,分母不能为零。故为 " + e.getMessage());
		}
	}
	
	public static double clclt(double A, String operator, double C) {
		double D = 0;
			switch(operator) {
			case "+" :
				D = A + C;
				break;
			case "-" :
				D = A - C;
				break;
			case "*" :
				D = A * C;
				break;
			case "/" :
					D = A / C;
				break;
			}
		return D;
	}
}


联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号