数组的两种定义方式,求数字的字符数

1.第一种,不知道具体的内容
         String[] names = new String[34];
        double[] scores = new double[34];
        char[] sexs = new char[34];
        int[] ages = new int[34];
      一般配合for循环来给数组赋值。
2.第二种,知道具体的内容,直接赋值
        String[] names1 = { "张三", "李四", "王五", "赵四" };
        double[] scores1 = { 85, 98, 76, 90 };
        char[] sexs1 = { '男', '男', '男', '女' };
        int[] ages1 = { 23, 24, 25, 26 };
//数组
        double[] scores = new double[10];
        for(int i = 0;i<scores.length;i++){
            scores[i] = Math.random();
        }


        String[] cities = {"武汉","上海"};


        //输出变量
        for(int i = 0;i<scores.length;i++){
            System.out.println(scores[i]);
        }


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


        //输出foreach的方式
        //打印分数
        for(double score : scores){
            System.out.println(score);
        }


        //打印城市
        for(String city :cities){
            System.out.println(city);
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值