建立类Max,利用方法重载建立max()方法分别输出2个数中的最大值以及3个数中的最大值。

来源:互联网 发布:navicat 看不到数据库 编辑:程序博客网 时间:2024/06/15 16:05

public class  Max{

int a,b,c;

void setA(int a){

this.a=a;

}

void setB(int b){

this.b=b;

}

void setC(int c){

this.c=c;

}

void Max(int x,int y){

int s;

if (x>y)

s=x;

else

s=y;

System.out.println("最大的数是"+s);

}

void Max(int x,int y,int z){

int s,s1;

if (x>y)

s=x;

else

s=y;

if(s>z)

s1=s;

else

s1=z;

System.out.println("最大的数是"+s1);

}

 

 

public static void main(String[] args){

Max s1=new Max();

s1.Max(3, 4);

s1.Max(3,4,5);

 

}

0 0
原创粉丝点击