集册 Java实例教程 初始化两个

初始化两个

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

564
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
初始化二维数组。

public class Main 

{

   // create and output two-dimensional arrays

   public static void main(String[] args)
   /*
    from 时 代      J a v a   公   众 号 - nowjava.com 
   */

   {

      int[][] array1 = {{1, 2, 3}, {4, 5, 16}};        

      int[][] array2 = {{11, 12}, {13}, {14, 5, 6}}; 


      System.out.println("Values in array1 by row are");

      outputArray(array1); // displays array1 by row

   

      System.out.printf("%nValues in array2 by row are%n");

      outputArray(array2); // displays array2 by row

   } 

   /**
    * 时代Java 提 供 
   **/

   // output rows and columns of a two-dimensional array

   public static void outputArray(int[][] array)

   {

      // loop through array's rows

      for (int row = 0; row < array.length; row++) 

      {

         // loop through columns of current row

         
展开阅读全文