共計 257 個字符,預計需要花費 1 分鐘才能閱讀完成。
你可以使用循環遍歷數組,然后比較每個元素的值來找到最大值。
以下是一個使用 Java 的示例代碼:
public class Main {public static void main(String[] args) {int[] array = {5, 2, 9, 1, 8};
int max = array[0]; // 假設第一個元素為最大值
for (int i = 1; i max) {max = array[i];
}
}
System.out.println("數組中最大的值為:" + max);
}
}
運行以上代碼,將輸出:
數組中最大的值為: 9
丸趣 TV 網 – 提供最優質的資源集合!
正文完