zoukankan      html  css  js  c++  java
  • 作业5.1

    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class Zhidao {
    
        public static void main(String[] args) {
    
            Scanner scanner = new Scanner(System.in);
            try {
                System.out.print("请输入第一个数:");
                double x = scanner.nextDouble();
                System.out.print("请输入第二个数:");
                double y = scanner.nextDouble();
                System.out.print("请输入运算符:");
                String s = scanner.next();
                char z = s.charAt(0);
                js.yunsuan(x, y, z);
            } catch (Exception e) {
                System.out.println("请输入正确的数据!");
    
            }
    
        }
    
    }
    
    
    import java.text.DecimalFormat;
    
    public class js {
    
        public static void yunsuan(double x, double y, Character z) {
            DecimalFormat r = new DecimalFormat();
            r.applyPattern("#0.00");
            if (z.equals('+')) {
                System.out.println(x + "+" + y + "=" + r.format((x + y)));
            } else if (z.equals('-')) {
                System.out.println(x + "-" + y + "=" + r.format((x - y)));
            } else if (z.equals('*')) {
                System.out.println(x + "*" + y + "=" + r.format((x * y)));
            } else if (z.equals('/')) {
                if (y == 0) {
                    System.out.println("被除数不能为0");
                } else {
                    System.out.println(x + "/" + y + "=" + r.format((x / y)));
                }
    
            } else {
                System.out.println("无法识别改运算符");
            }
        }
    
    }


    同伴:201306114456,刁怿。
    微博:http://www.cnblogs.com/diaoyi/
  • 相关阅读:
    CentOS 出错处理
    g13 root
    修复误删系统文件
    c++ list sort方法
    批量修改outlook联系人头像,并同步手机
    IT大牛们 学术搜索
    oracle 表空间操作
    CentOS 5.5 安装MPICH2\MRNet\Launchmon时遇到的问题
    自我反省
    积累航程
  • 原文地址:https://www.cnblogs.com/chenqiuliang/p/4468243.html
Copyright © 2011-2022 走看看