| 12345678910111213141516171819 |
- /**
- * @author WanJl
- * @version 1.0
- * @title HomeWork08
- * @description 7月15日作业:定义一个整数数组 `{3, 8, 1, 9, 4, 7, 2}`,找出数组中的最大值并输出。
- * @create 2026/7/16
- */
- public class HomeWork08 {
- public static void main(String[] args) {
- int[] arr={3, 8, 1, 9, 4, 7, 2};
- int max=arr[0]; //作为最大值
- for (int i = 1; i < arr.length; i++) {
- if(arr[i]>max){ //如果某个元素比最大值max还大
- max=arr[i]; //就把这个值赋值给max
- }
- }
- System.out.println(max);
- }
- }
|