import java.util.Scanner; public class Calc { public double add(double a,double b){ return a+b; } public double red(double a,double b){ return a-b; } public double ride(double a,double b){ return a*b; } public double except(double a,double b){ return a/b; } public static void main(String[] args) { Calc calc = new Calc(); while(true){ System.out.println("请输入+ - * /或quit退去计算器"); Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); if(s.equals("quit")){ System.out.println("感谢使用"); break; } System.out.println("请输入两个数"); Scanner scan1 = new Scanner(System.in); double a = scan1.nextDouble(); Scanner scan2 = new Scanner(System.in); double b = scan2.nextDouble(); switch (s){ case "+": System.out.println(a+s+b+"="+calc.add(a,b)); break; case "-": System.out.println(a+s+b+"="+calc.red(a,b)); break; case "*": System.out.println(a+s+b+"="+calc.ride(a,b)); break; case "/": System.out.println(a+s+b+"="+calc.except(a,b)); break; default: System.out.println("请重新输入"); break; } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)