class ArrayTest
{
public static void main(String[] args)
{
int[] arr = {1,2,3,4,5,6,7};
double[] ar = {1.1,2.2,3.3,4.4,5.5,6.6};
int max = getMax(arr);
System.out.println("max="+max);
double max2 = getMax(ar);
System.out.println("max2="+max2);
}
public static int getMax(int[] arr)
{
int max = 0;
for(int x = 1;x<arr.length;x++)
{
if(arr[x]>arr[max])
max = x;
}
return arr[max];
}
public static double getMax(double[] ar)
{
return getMax(ar);//利用函数重载,但是这个返回值不对.
}
}
|
|