提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
返回数组的最大值。
//package com.nowjava; public class Main {/*来 自 时 代 Java 公 众 号 - nowjava.com*/ public static void main(String[] argv) throws Exception { double[] v = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000, 37.1234, 67.2344, 68.34534, 69.87700 }; System.out.println(max(v)); } /** * Returns the maximum of an array. */ public static double max(double[] v) { double max = v[0]; /** from n o w j a v a . c o m - 时代Java**/ for (int i = 1; i < v.length; i++) { if (max < v[i]) { max = v[i]; } } return (max); } /** * Returns the maximum of an array. */ public static double max(double[][] v) { double max = max(v[0]); for (int i = 1; i < v.length; i++) { if (max < max(v[i])) { max = max(v[i]); } } return (max); } /** * Returns the maximum of an array. */ public static int max(int[] v) { int max = v[0]; for (int i = 1; i < v.length; i++) { if (max < v[i]) { max = v[i]; } } return (max); } /** * Returns the maximum of an array. */ public