关于Java while循环遍历数组类问题,如图

2025-02-25 06:35:53
推荐回答(2个)
回答1:

解释再注释中:

public class Test {
 
    public static void main(String[] args) {
 
        String[] strings = { "白鹭", "丹顶鹤", "黄鹂", "乌鸦" };
 
        int index = 0;
        System.out.print("我花园里有好多种鸟,种类大约包括:");
         
        while (index < strings.length) {
 
            /**
             *  index++:自增,此运算符每执行一次index就会加1
             *  strings[index++]:strings[0]从第一个开始,依次取出数组中的所有元素
             *  "    "代表每个元素之间用空格分开
             */
            System.out.print(strings[index++] + "    ");
        }
    }
}

执行结果:


回答2:

先进性index++运算,在对数组下表为index的数据进行不换行输出

index=index+1;
system.out.print(aves[index]+" ")