请教高手一个java编程问题
编写一个JAVA程序,反映出方法重载的使用特点,该程序包含多个重载的加法运算,列如:整型加法;实型加法,以及混合型加法(比如:add(inta,intb,doublec)...
编写一个JAVA程序,反映出方法重载的使用特点,该程序包含多个重载的加法运算,
列如:整型加法;实型加法,以及混合型加法(比如:add(int a,int b,double c)).
从中体会方法重载的用法和优点。程序运行时的效果如下所示:
无参加法:1+2=3
整型加法:3+6=9
实型加法:2.1+5.3=7.4
混合加法:3+6+2.2=11.2 展开
列如:整型加法;实型加法,以及混合型加法(比如:add(int a,int b,double c)).
从中体会方法重载的用法和优点。程序运行时的效果如下所示:
无参加法:1+2=3
整型加法:3+6=9
实型加法:2.1+5.3=7.4
混合加法:3+6+2.2=11.2 展开
1个回答
展开全部
public class JiaFa {
public void jiafa1()
{
System.out.println("1+2=3");
}
public void jiafa1(int a,int b)
{
System.out.println(a+"+"+b+"="+(a+b));
}
public void jiafa1(double a,double b)
{
System.out.println(a+"+"+b+"="+(a+b));
}
public void jiafa1(int a,int b,double c)
{
System.out.println(a+"+"+b+"+" +c +"="+(a+b+c));
}
public static void main(String[] args) {
JiaFa a=new JiaFa();
a.jiafa1();
a.jiafa1(3, 6);
a.jiafa1(2.1, 5.3);
a.jiafa1(3, 6,2.2);
}
}
public void jiafa1()
{
System.out.println("1+2=3");
}
public void jiafa1(int a,int b)
{
System.out.println(a+"+"+b+"="+(a+b));
}
public void jiafa1(double a,double b)
{
System.out.println(a+"+"+b+"="+(a+b));
}
public void jiafa1(int a,int b,double c)
{
System.out.println(a+"+"+b+"+" +c +"="+(a+b+c));
}
public static void main(String[] args) {
JiaFa a=new JiaFa();
a.jiafa1();
a.jiafa1(3, 6);
a.jiafa1(2.1, 5.3);
a.jiafa1(3, 6,2.2);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询