zoukankan      html  css  js  c++  java
  • 课堂,重载 模拟简单计算器

    package liu0919;
    //计算器
    
    public class Jisuanqi {
    	
    	//属性
    	//型号,品牌,大小
    	
    	//重载
    	//1.方法同名不同参
    	//2.返回类型和重载无关;
    	//3.多态的一种表现形式
    	//4.构造方法也可以重载;
    	//方法
    	//加法运算
    	public int Jia(int a,int b)
    	{
    		return a+b;
    	}
    	public int Jia(int x,int y,int z)//由于参数个数不同所以和上面的方法不冲突
    	{
    		return x+y+z;
    	}
    	
    	//浮点加法运算
    	public double Jia(double a,double b)//由于数据类型不一样,即使参数个数相同也不会与第一个方法不冲突
    	{
    		return a+b;
    	}
    	public int max(int a,int b)
    	{
    		if(a>b)
    		{
    			return a;
    		}
    		else
    		{
    			return b;
    		}
    	}
    	public double max(double a,double b)
    	{
    		if(a>b)
    		{
    			return a;
    		}
    		else
    		{
    			return b;
    		}
    	}
    	public double max(double a,double b,double c)
    	{
    		if(a>b&&a>c)
    		{
    			return a;
    		}
    		else if(b>a&&b>c)
    		{
    			return b;
    		}
    		else
    		{
    			return c;
    		}
    	}
    }
    

      

    package liu0919;
    
    public class Jiansuanqijianyan {
    
    	public static void main(String[] args) 
    	{
    		Jisuanqi jsq=new Jisuanqi();
    		
    		//调用整数加法
    		System.out.println("123+456="+jsq.Jia(123,456));
    		
    		//调用浮点数加法
    		System.out.println("123.45+456.78="+jsq.Jia(123.45,456.78));
    		
    		
    		Jisuanqi ma=new Jisuanqi();
    		System.out.println("45和23="+ma.max(45, 23));
    	}
    
    }
    

      

  • 相关阅读:
    回溯法之迷宫问题
    一个.net的正则表达式测试工具
    关于FeedSky话题广告
    google notebook更新了&digg notebook
    近日,来北京近一月
    城堡技术论坛(castle.org.cn)上线!
    玉龙雪山
    消息队列(Message Queue)
    Mac Theme for Google Reader
    开始学习npetshop2
  • 原文地址:https://www.cnblogs.com/liuyanzeng/p/5886727.html
Copyright © 2011-2022 走看看