zoukankan      html  css  js  c++  java
  • 作业5 测试与封装 四则运算

    package aaa;
    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Dada {
    	
    	public static void main(String[] args) {
    		int condition=1 ;
    		Dada dada = new Dada();
    		Scanner scanner = new Scanner(System.in);
    		while(condition==1){
    		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);
    		Test test=new Test();
    		test.yunsuan(x, y, z);
    		System.out.print("是否继续?1是  其他为否");
    		condition = scanner.nextInt();}
    		}
    	}
    
    
    
    package aaa;
    
    import java.text.DecimalFormat;
    public class Test{
    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("无法识别改运算符");
    		}
    	
    	}}
    	
    

      没有找到小伙伴,因为很多同学都回去了。这是我做的一个小程序,虽然没有很多功能,但是这个程序有很多可以改进以及可以添加很多功能。

  • 相关阅读:
    2.2 建立示例数据库
    2.1.4 基本概念
    8. 在NOARCHIVELOG模式下用户管理的备份与恢复
    2.1.2 系统全局区
    考过042
    ORA1157错误解决手册(转)
    4. 用户管理的备份
    Kohana之LOG使用
    jq插件之easing
    Svn服务器之必须提交更改日志篇
  • 原文地址:https://www.cnblogs.com/xhy1210/p/4468646.html
Copyright © 2011-2022 走看看