1
0

Javaで「多次元配列を作成する」の動作を確認してみた

Posted at

概要

Javaで「多次元配列を作成する」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

JSample7_1.java
class JSample7_1{
  public static void main(String[] args){
    int[][] num = new int[2][];

    num[0] = new int[3];
    num[0][0] = 78;
    num[0][1] = 64;
    num[0][2] = 59;

    num[1] = new int[3];
    num[1][0] = 58;
    num[1][1] = 92;
    num[1][2] = 82;
    
    for (int i = 0; i < 2; i++){
      for (int j = 0; j < 3; j++){
        System.out.println("num[" + i + "][" + j + "] = " + num[i][j]);
      }
    }
  }
}

以下のコマンドを実行しました。

$ javac JSample7_1.java 
$ java JSample7_1 
num[0][0] = 78
num[0][1] = 64
num[0][2] = 59
num[1][0] = 58
num[1][1] = 92
num[1][2] = 82

まとめ

何かの役に立てばと。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0