数组的声明、初始化

xiaoxiao2021-02-28  120

package com.lrq; import org.omg.Messaging.SyncScopeHelper; /** * * @author 李瑞琦 随机生成[1-10000]的数100个,并找出最大的数 * */ public class TestArray1 { public static void main(String[] args) { // 声明数组的长度 int length = 100; int[] a = new int[length]; // 遍历数组,往数组里面存值 for (int i = 0; i < a.length; i++) { // 需强制类型转换 a[i] = (int) (Math.random() * 10000 + 1); } // 首先声明最大的数组 int max = a[0]; // 遍历集合里面的数组,找出最大的 for (int i = 1; i < a.length; i++) { if (a[i] > max) { max = a[i]; } } System.out.println("最大的数为" + max); } }
转载请注明原文地址: https://www.6miu.com/read-37001.html

最新回复(0)