数组笔记及创建

package itws13;

public class test {
    /*   数组的创建
        //第一种(包含2种形式):静态初始化,数组中的元素确定,数组的长度由给定的元素的个数来确定
        //形式1
        public static void main(String[] args) {
            int[] arr1 = {1, 3, 5, 6};
            //形式2
            int[] arr2 = new int[]{21, 34, 2, 56};
            //不能拆开书写,声明和赋值只能在一起
            //int[] arr3;
            //arr3={11,22,33}

          //可以拆开
            int[] arr5;
            arr5 = new int[]{123, 23, 32};

            //第2种:动态初始化,数组的长度由程序员指定,数组的元素由程序根据类型自动赋默认值
            //数值类型:一般默认值就是0   0.0
            //String类型: 一般就是 null
            String[] arr4=new String[4];
        }

     */
//数组的使用
   /* public static void main(String[] args) {
        double[] arr1 = new double[20];
        System.out.println(arr1[4]);

        String[] arr2 = {"呵呵", "哈哈", "你好", "再见"};
        System.out.println(arr2[3]);
        System.out.println("====================================");
        //注意:索引不要超过数组长度-1,否则:ArrayIndexOutOfBoundsException 索引越界
        //  System.out.println(arr2[4]);

        for (int i=0;i<arr2.length;i++){
            String s = arr2[i];
            System.out.println(s);
        }


    }*/
//数组的灵活
   /* public static void main(String[] args) {

        double[] scores = new double[6];
        scores[0] = 65.4;
        scores[1] = 1.7;
        //正常遍历
        for (int i = 0; i < scores.length; i++) {
            System.out.println(scores[i]);
        }
        System.out.println("=================");
        //倒着遍历
        for (int i = scores.length - 1; i >= 0; i--) {
            System.out.println(scores[i]);
        }
        System.out.println("=================");
        //减2 跳跃遍历
        for (int i = scores.length - 1; i >= 0; i = i - 2) {
            System.out.println(scores[i]);
        }
    }*/

//例题

    public static void main(String[] args) {
     int a=1;
     int[] arr={10};
     test t=new test();
    t.change(a, arr);
//        System.out.println(change);

        System.out.println(a);
        System.out.println(arr[0]);

    }
    public void change(int i,int[]arr){
        i=2;
        arr[0]=30;
        System.out.println(i);

    }

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值