其他分享
首页 > 其他分享> > 二维数组练习五个人,姓名年龄身高

二维数组练习五个人,姓名年龄身高

作者:互联网

二维数组练习

代码:

  package com.guoba.testhello;

import java.util.Scanner;

/*
5学校3班级每班10学生
 */
public class Demo09 {
    public static void main(String[] args) {
        String[][] arr =new String[5][3];
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入姓名年龄身高");
        int k= 1;
        for (int i = 0;i<arr.length;i++){

            for (int j = 0; j < arr[i].length; j++) {

                System.out.println("第"+k+"组数据");
                ++k;
                arr[i][j]= scanner.next();
            }
        }
        System.out.println("[");
        for (int i = 0; i < arr.length; i++) {

            for (int j = 0; j <arr[i].length ; j++) {
                if (j == arr[i].length - 1) {
                    System.out.print(arr[i][j]);
                } else {
                    System.out.print(arr[i][j] + ",");
                }
            }
            System.out.println();

        }System.out.print("]");

    }
}

标签:String,int,System,二维,数组,身高,Scanner
来源: https://www.cnblogs.com/guobabiancheng/p/15656179.html