zoukankan      html  css  js  c++  java
  • 20155206 实验一《Java开发环境的熟悉》实验报告

    实验内容

    使用JDK编译、运行简单的Java程序

    使用IDEA 编辑、编译、运行、调试Java程序。

    实验代码

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

    public class math {

    public static void main(String[] args) {
    String condition = "";
    math math = new math();
    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);
    math.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("无法识别改运算符");
    }
    }

    }`

  • 相关阅读:
    poj 2488 A Knight's Journey( dfs )
    poj 2676 Sudoku ( dfs )
    poj 3087 Shuffle'm Up ( map 模拟 )
    poj 1426 Find The Multiple( bfs )
    poj 3126 Prime Path( bfs + 素数)
    Atcoder ARC-063
    Atcoder ARC-062
    Atcoder ARC-061
    Atcoder ARC-060
    Atcoder ARC-058
  • 原文地址:https://www.cnblogs.com/zf011/p/6685854.html
Copyright © 2011-2022 走看看