找出数组中的最大值


package chapter7;

/*
* 找出数组中的最大值
*/
public class TestArrayMax {
public static void main(String[] args) {
// 定义一个数组
int[] a = { 1, 9, 5, 4, 3, 0, 2 };
// 定义一个int类型的变量的数组并赋值0;
int max = a[0];
// for循环遍历数组,判断数组长度
for (int i = 0; i < a.length; i++) {
// 定义一个if条件判断定义的数组
if (max < a[i]) {
max = a[i];
System.out.println("max的值是:" + max);
}
}

}
}

-------------------打印-----------------------

max的值是:9


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM