• java 实现一个简易计算器


    import java.util.Scanner;
    public
    class Test { public static void main(String[] args) { count(); } public static void count() { Scanner input1 = new Scanner(System.in); System.out.println("输入一个数"); double a = input1.nextDouble(); while (true) { Scanner input3 = new Scanner(System.in); System.out.println("提示:请输入您的操作"); System.out.println("+"); System.out.println("-"); System.out.println("*"); System.out.println("/"); System.out.println("F:退出"); String str = input3.nextLine(); char chr = str.toCharArray()[0]; switch (chr) { case '+': a = add(a); System.out.println("当前结果为:"+a); break; case '-': a = subtrace(a); System.out.println("当前结果为:"+a); break; case '*': a = ride(a); System.out.println("当前结果为:"+a); break; case '/': a = except(a); System.out.println("当前结果为:"+a); break; case 'F': System.out.println("结果:" + a); System.exit(-1); default: System.out.println("操作错误!"); break; } } } public static double add(double a) { Scanner input2 = new Scanner(System.in); System.out.println("输入一个数"); double b = input2.nextDouble(); return (a + b); } public static double subtrace(double a) { Scanner input2 = new Scanner(System.in); System.out.println("输入一个数"); double b = input2.nextDouble(); return (a - b); } public static double ride(double a) { Scanner input2 = new Scanner(System.in); System.out.println("输入一个数"); double b = input2.nextDouble(); return a * b; } public static double except(double a) { Scanner input2 = new Scanner(System.in); System.out.println("输入一个数"); double b = input2.nextDouble(); return a / b; } }

  • 相关阅读:
    Maven项目中Spring整合Mybatis
    java中,方法可以访问他的类对象的任何私有特性
    SpringBoot之整合Mybatis(增,改,删)
    SpringBoot之整合Mybatis
    SpringBoot之简单入门
    puppet-master搭建
    基于weka的文本分类实现
    static关键字用法
    Vmware /CentOS访问Windows中的文件
    异常备忘
  • 原文地址:https://www.cnblogs.com/ywloveby/p/6091343.html
Copyright © 2020-2023  润新知