Object-Oriented Programming Hands-on Exercise 1 (Function Overloading)

Problem Description
Use arrays and function overloading to find the maximum value of 5 numbers (respectively consider the cases of integers, single-precision, and long integers).
Input
Input 5 int-type integers, 5 float-type real numbers, and 5 long-type positive integers respectively.
Output
outputs the maximum value of 5 int-type integers, the maximum value of 5 float-type real numbers, and the maximum value of 5 long-type positive integers.
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

import java.util.*;

class Cul{

    public static int hh(int a[]) {
        int max = a[0];
        for(int i = 1; i < 5; i++) {
            if(max < a[i]) {
                max = a[i];
            }
        }
        return max;
    }
    public static float hh(float a[]) {
        float max = a[0];
        for(int i = 1; i < 5; i++) {
            if(max < a[i]) {
                max = a[i];
            }
        }
        return max;
    }
    public static long hh(long a[]) {
        long max = a[0];
        for(int i = 1; i < 5; i++) {
            if(max < a[i]) {
                max = a[i];
            }
        }
        return max;
    }

}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int [] a = new int[5];
        float[] b = new float[5];
        long [] c = new long[5];
        for(int i = 0; i < 5; i++) {
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < 5; i++) {
            b[i] = sc.nextFloat();
        }
        for(int i = 0; i < 5; i++) {
            c[i] = sc.nextLong();
        }

        System.out.println(Cul.hh(a));
        System.out.println(Cul.hh(b));
        System.out.println(Cul.hh(c));

        sc.close();
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325650810&siteId=291194637