您的位置:首页 > 编程语言 > Java开发

sdut_java_面向对象程序设计上机练习一(函数重载)

2017-03-31 20:18 633 查看


面向对象程序设计上机练习一(函数重载)

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic


Problem Description

利用数组和函数重载求5个数最大值(分别考虑整数、单精度、长整数的情况)。


Input

分别输入5个int型整数、5个float 型实数、5个long型正整数。


Output

分别输出5个int型整数的最大值、5个float 型实数的最大值、5个long型正整数的最大值。


Example Input

11 22 666 44 55
11.11 22.22 33.33 888.88 55.55
1234567 222222 333333 444444 555555



Example Output

666
888.88
1234567
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int a = in.nextInt();
int a1 = in.nextInt();
int a2 = in.nextInt();
int a3 = in.nextInt();
int a4 = in.nextInt();
float f = in.nextFloat();
float f1 = in.nextFloat();
float f2 = in.nextFloat();
float f3 = in.nextFloat();
float f4 = in.nextFloat();
long l = in.nextLong();
long l1 = in.nextLong();
long l2 = in.nextLong();
long l3 = in.nextLong();
long l4 = in.nextLong();
Max max = new Max();
System.out.println(max.getMax(a, a1, a2, a3, a4));
System.out.println(max.getMax(f, f1, f2, f3, f4));
System.out.println(max.getMax(l, l1, l2, l3, l4));
in.close();
}

}

class Max {
int max;
float max1;
long max2;

public Max(){
max = 0;
max1 = 0;
max2 = 0;
}

public int getMax( int a, int a1, int a2, int a3, int a4 ){
max = a;
if( a1>max )
max = a1;
if( a2>max )
max = a2;
if( a3>max )
max = a3;
if( a4>max )
max = a4;
return max;
}

public float getMax( float a, float a1, float a2, float a3, float a4 ){
max1 = a;
if( a1>max1 )
max1 = a1;
if( a2>max1 )
max1 = a2;
if( a3>max1 )
max1 = a3;
if( a4>max1 )
max1 = a4;
return max1;
}

public long getMax( long a, long a1, long a2, long a3, long a4 ){
max2 = a;
if( a1>max2 )
max2 = a1;
if( a2>max2 )
max2 = a2;
if( a3>max2 )
max2 = a3;
if( a4>max2 )
max2 = a4;
return max2;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: