zoukankan      html  css  js  c++  java
  • Java 之数组

    public class ArrayTest {
        public static void main(String[] args) {
            arrayTest1();
        }
    
        //数组测试
        //数组一旦定义,其长度不可以改变
        //获取数组长度的方法是调用数组的length属性
        //数组的下标是从0开始,数组最大下标等于数组长度-1
        //不可以删除数组中的元素
        static void arrayTest1(){
            //第一种
            int[] array1 = new int[2];
            //第二种
            String[] array2 = new String[]{ "gongyg", "gumd", "gongxy", "gongxh"};
            for (int i = 0; i < array2.length; i++) {
                System.out.println(array2[i]);
            }
            for (String str1:
                 array2) {
                System.out.println(str1);
            }
            //第三种
            int[] array3 = { 11, 13, 15 };
            int k = 0;
            while (k < array3.length) {
                System.out.println(array3[k]);
                k++;
            }
        }
    
        /**
         * 二位数组 外层必须指定长度
         */
        static void arrayTest2(){
            //外层必须定义数组长度
            int[][] array1 = new int[2][];
            array1[0] = new int[]{1,2,3};
            array1[1] = new int[]{3,4};
    
            int[][] array2 = new int[][]{{1, 2, 3},{4, 5, 6, 7}};
    
            int[][] array3 = {{1, 2, 3}, {4, 5}};
        }
    }
  • 相关阅读:
    leetcode 567 滑动窗口
    田忌赛马
    去除CSDN无用的打印边框,显示数据
    操作系统博客清单
    OpenKiwi学习笔记
    开源minigui移植
    嵌入式GUI总结
    short int 变量的取值范围
    68 进程等待机制的实现 下
    67 进程等待机制的实现 上
  • 原文地址:https://www.cnblogs.com/gygtech/p/13430504.html
Copyright © 2011-2022 走看看