package com.inmind; /* 1.定义一个整型数组,传入一些固定的值 2.使用数组的遍历,获取到数组中最大的值 */ public class Demo04_array_test { public static void main(String[] args) { //定义一个整型数组 int[] arr = {10,20,30,50,100,-100,300}; //获取数组中的最大值 //定义一个变量,将数组的第一位数据保存到变量假定是最大 int max = arr[0]; //数组的遍历 for (int i = 1; i < arr.length; i++) { //取出数组中每个元素 int temp = arr[i]; if (temp > max) { max = temp; } } System.out.println(max); } }