zoukankan      html  css  js  c++  java
  • 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; } }

  • 相关阅读:
    双向链表循环
    双向链表的删除操作
    双向链表的插入操作
    双向链表的结构
    双向链表的删除操作
    双向链表循环
    OD使用教程17 调试篇17
    OD使用教程17 调试篇17
    双向链表的结构
    独生子女证办理
  • 原文地址:https://www.cnblogs.com/ywloveby/p/6091343.html
Copyright © 2011-2022 走看看