Problem Description
利用数组和函数模板求5个数最大值(分别考虑整数、单精度、长整数的情况)。
Input
分别输入5个int型整数、5个float 型实数、5个long型正整数。
Output
分别输出5个int型整数的最大值、5个float 型实数的最大值、5个long型正整数的最大值。
Sample Input
11 22 666 44 55
11.11 22.22 33.33 888.88 55.55
1234567 222222 333333 444444 555555
Sample Output
666
888.88
1234567
AC代码:
import java.util.Scanner;
class A {
int a;
float b;
long c;
public void setA(int a) {
this.a = a;
}
public void setB(float b) {
this.b = b;
}
public void setC(long c) {
this.c = c;
}
public int Sort1(int x) {
if (a < x)
a = x;
return a;
}
public float Sort2(float x) {
if (b < x)
b = x;
return b;
}
public long Sort3(long x) {
if (c < x)
c = x;
return c;
}
}
public class Main {
public static void main(String[] args) {
Scanner mi = new Scanner(System.in);
A a = new A();
A b = new A();
A c = new A();
int[] a1 = new int[5];
float[] b1 = new float[5];
long[] c1 = new long[5];
for (int i = 0; i < 5; i++) {
a1[i] = mi.nextInt();
}
for (int i = 0; i < 5; i++) {
b1[i] = mi.nextFloat();
}
for (int i = 0; i < 5; i++) {
c1[i] = mi.nextLong();
}
a.setA(a1[0]);
for (int i = 1; i < 5; i++) {
a.Sort1(a1[i]);
}
b.setB(b1[0]);
for (int i = 1; i < 5; i++) {
b.Sort2(b1[i]);
}
c.setC(c1[0]);
for (int i = 1; i < 5; i++) {
c.Sort3(c1[i]);
}
System.out.println(a.a + "\n" + b.b + "\n" + c.c + "\n");
mi.close();
}
}
————
余生还请多多指教!