zoukankan      html  css  js  c++  java
  • 四则运算借鉴

    import java.text.DecimalFormat;
    import java.util.Scanner;

    public class Zhidao {

    public static void main(String[] args) {
    String condition = "";
    Zhidao zhidao = new Zhidao();
    do{
    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);
    zhidao.yunsuan(x, y, z);
    }catch(Exception e){
    System.out.println("请输入正确的数据!");
    }
    System.out.print("是否继续?continue:继续,任意字符:结束");
    condition = scanner.next();

    }while("continue".equals(condition));
    }

    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("无法识别改运算符");
    }
    }

    }
  • 相关阅读:
    200. Number of Islands(DFS)
    DoubleDQN---tensorflow实现
    133. Clone Graph(图的复制)
    python deque
    136. Single Number(位运算)
    C++中位运算
    anacoda 安装默认源中没有的包
    kali系统安装图文教程
    C#基础|初探反射
    一般处理程序(ashx)和页面处理程序(aspx)的区别
  • 原文地址:https://www.cnblogs.com/32zmx/p/6541815.html
Copyright © 2011-2022 走看看