class BianLi {
public static void main(String[] args) {
int[] arr = {1,23,34,36,30,45};
int[] arr2 = {12,23,45,78,56};
//printArray(arr);
//System.out.println("-------------");
//printArray(arr2);
int max = getMax_2(arr2);
System.out.println(max);
//int max = getMax_2(arr);
//System.out.println(max);
}
public static void printArray(int[] arr){
for (int x = 0;x < arr.length ;x++ )
{
System.out.println(arr[x]);//数组的遍历
}
}
/*public static int getMax (int[] arr){
int max = arr[0];
for (int x=1;x< arr.length ;x++ )
{
if (arr[x]>max)
{
max =arr[x];
}
}
return max;
}*/
public static int getMax_2(int[] arr){
int max = 0;
for (int x = 1;x < arr.length ;x++ )
{
if (arr[x] > arr[max])
{
max = x;
}
}
return arr[max];
}
}
|
|