Three ways to find the maximum and minimum values in the array
Third personally I feel very good.
public class ArrayAlg { public static void main (String [] args) { // find the maximum value of the array Double [] = Doubles 22.1,32.5,56.2,45.2,78.2 { }; / * Method a: Arrays.sort (doubles ); System.out.println (of Arrays.toString (Doubles)); System.out.println ( "maximum value is:" + Doubles [-doubles.length. 1]); System.out.println ( "minimum of: "Doubles + [0]); * / / * method two: Double Doubles = max [0]; for (int I = 0; I <-doubles.length. 1; I ++) { IF (max <Doubles [I +. 1 ]) { max = Doubles [I +. 1]; } } System.out.println ( "maximum value is:" + max); double min=doubles[0]; for (int i=0;i<doubles.length-1;i++){ if (min>doubles[i+1]){ min=doubles[i+1]; } } System.out.println("最小值为:"+min); */ /*方法三:double min=Double.POSITIVE_INFINITY; double max=Double.NEGATIVE_INFINITY; for (double d:doubles){ if (min>d){ min=d; } if (max<d){ max=d; } } System.out.println("最大值为:"+max+"最小值"+min); */ } }