class ArrayTest
{
public static int MaxZhi(int[] array){
int max=array[0];
for (int x=1;x<array.length;x++ )
{
if (max<array[x])
{
max=array[x];
}
}
return max;
}
public static int MinZhi(int[] array){
int min=array[0];
for (int x=1;x<array.length;x++ )
{
if (min>array[x])
{
min=array[x];
}
}
return min;
}
public static void main(String[] args)
{
int[] array={443,546,7,4,3,5,34,3432,654,765,987};
int max=MaxZhi(array);
System.out.println(max);
int min=MinZhi(array);
System.out.println(min);
for(int x=0;x<array.length;x++)
{
if (array[x]==max)
{
System.out.println("最大值得索引是"+x);
}
if (array[x]==min)
{
System.out.println("最小值得索引是"+x);
}
}
}
}
|
|