菁英科技(卓目鸟学苑)- 专注软件测试菁英教育

标题: java-魏清-20210308 [打印本页]

作者: 5269    时间: 2021-3-8 20:20
标题: java-魏清-20210308
package day02;

import java.util.Arrays;

/*
数组
    固定
    相同
*/
public class Demo05 {
    public static void main(String[] args) {
        int[] ids = {1001, 1002, 1003, 1004};
        System.out.println(ids[0]);
        System.out.println(ids[1]);
        System.out.println(ids[2]);
        System.out.println(ids[3]);
//        System.out.println(ids[4]); // ArrayIndexOutOfBoundsException

        String[] names = {"aaa", "bbb", "ccc", "ddd"};
        System.out.println(names.length);   //

        // 数组的遍,for,使用索引遍
        for (int i = 0; i < names.length; i++) {
            System.out.println("hello," + names);
        }

        // foreach,每次取数组中的一元素
        for (String name : names) {
            System.out.println("hello," + name);
        }

        // 数组中的最大/最小
        int[] nums = {10, 6, 10, 8, 100, 70, 60, 30};
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums > max) {
                max = nums;
            }
        }
        System.out.println("最大值为: " + max);

        int min = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums < min) {
                min = nums;
            }
        }
        System.out.println("最小值为: " + max);

  






欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/) Powered by Discuz! X3.4