package com.cnic.stream.code;
/***
* 求任意数组中的最大值
*/
public class GetArrayMaxNum {
public static void main(String[] args) {
// 1.定义一个数组
int[] arr = {90,152,43,2,44,8,6666};
// 2.选取数组中的第一个元素开始比较
int max = arr[0];
// 3.依次遍历数组中的元素
for (int i = 0; i < arr.length; i++) {
// 4.判断当前原色与目前最大值大小
if (arr[i] > max) {
// 5.如果当前数组元素大于max,就将次元素赋值给max
max = arr[i];
}
}
// 6.打印输出结果
System.out.println(max);
}
}
求任意数组中的最大值
最新推荐文章于 2023-04-24 08:00:00 发布