集册 Java实例教程 访问多元素

访问多元素

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

457
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
访问多维数组的元素

public class Main {

  public static void main(String[] args){

    int[][] ra = new int[3][];    //from 时 代 J a v a 公 众 号 - nowjava.com

    ra[0] = new int[2];

    ra[1] = new int[1];

    ra[2] = new int[3];

    

    // Populate the ragged array using for loops

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

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

        ra[i][j] = i + j;

      }

    }/*from 时代Java公众号 - nowjava.com*/


    // Print the array using for loops

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

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

 
展开阅读全文