集册 Java实例教程 创建二维数组

创建二维数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

556
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建二维数组

public class ArrayOfArraysDemo {/** 来自 时   代    Java - nowjava.com**/

    public static void main(String[] args) {

        String[][] cartoons = {

                { "Flintstones", "Fred", "Wilma", "Pebbles", "Dino" },

                { "Rubbles", "Barney", "Betty", "Bam Bam" },

                { "Jetsons", "George", "Jane", "Elroy", "Judy", "Rosie",

                        "Astro" },

                { "Scooby Doo Gang", "Scooby Doo", "Shaggy", "Velma",

                        "Fred", "Daphne" } };


        for (int i = 0; i < cartoons.length; i++) {

            System.out.print(cartoons[i][0] + ": ");

            for (int j = 1; j < cartoons[i].length; j++) {

                System.out.print(cartoons[i][j] + " ");/*from 时代Java - N o w  J a v a . c o m*/

            }

            System.out.println();

        }

    }

}


展开阅读全文