/**遍历数组,并打印到终端设备*/
public static void IterationInt(int[] arr){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+"\t");
}
}
/**求int数组中的平均值*/
public static int getArrayAvg(int[] arr){
int result = 0;
for (int i = 0; i < arr.length; i++) {
result +=arr[i];
}
return result/arr.length;
}
/**求int数组中的最大值*/
public static int getArrayMax(int[] arr){
int result = 0;
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result<arr[i]){
result = arr[i];
}
}
return result;
}
/**求double数组中的最大值*/
public static double getArrayMax(double[] arr){
double result = 0;
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result<arr[i]){
result = arr[i];
}
}
return result;
}
/**求String数组中的字符长度最大的元素*/
public static String getArrayMax(String[] arr){
String result = "";
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result.length()<arr[i].length()){
result = arr[i];
}
}
return result;
}
/**求int数组中的最小值*/
public static int getArrayMin(int[] arr){
int result = 0;
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result>arr[i]){
result = arr[i];
}
}
return result;
}
/**求double数组中的最小值*/
public static double getArrayMin(double[] arr){
double result = 0;
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result>arr[i]){
result = arr[i];
}
}
return result;
}
/**求String数组中的字符长度最小的元素*/
public static String getArrayMin(String[] arr){
String result = "";
result = arr[0];
for (int i = 0; i < arr.length; i++) {
if(result.length()>arr[i].length()){
result = arr[i];
}
}
return result;
}