[Java]lengthで配列の要素の数を取得する

2021年6月9日

書式
配列名.length
使用例

package com.arkgame.study;

public class ArrelemSample {

      public static void main(String[] args) {
            double[] dbArr = new double[4];

            dbArr[0] = 6.124;
            dbArr[1] = 7.25;
            dbArr[2] = 56.375;
            dbArr[3] = 78.900;

            System.out.println("配列の要素数:" + dbArr.length);

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

}

実行結果
配列の要素数:4
dbArr[0] = 6.124
dbArr[1] = 7.25
dbArr[2] = 56.375
dbArr[3] = 78.9

Java

Posted by arkgame