zoukankan      html  css  js  c++  java
  • Java多维数组

    public class multiarraysExample1
    {
    	public static void main(String[] args)
    	{
    		int[][] magicSquare =
    			{
    				{16,3,2,13},
    				{5,10,11,8},
    				{9,6,7,12 },
    				{4,15,14,1}
    			};
    		
    		for (int i = 0; i < magicSquare[0].length; i++)
    			{
    				System.out.printf("%d
    ", magicSquare[0][i]);
    			}
    
    		for (int i = 0; i< magicSquare.length; i++)
    		{
    			for (int j = 0; j< magicSquare[i].length; j++)
    			{
    				System.out.printf("%d
    ", magicSquare[i][j]);
    			}
    		}
    
    		for(int[] row: magicSquare)// loop through the rows first
    		{
    			for(int value : row) // loop through the elements of the row
    				System.out.printf("%d
    ", value);
    		}
    	}
    
    }
    

    To print out a quick-and-dirty list of the elements of a two-dimensional array, call:

    System.out.println(Arrays.deepToString(magicSquare)); // print out a quick-and-dirty
    
  • 相关阅读:
    python2和python3的区别
    星球大战
    [USACO]高低卡(金)High Card Low Card (Gold)
    学习笔记
    叶子的染色
    大问题
    ...
    考试前...
    [HAOI2010]计数
    [POI2006]OKR-Periods of Words
  • 原文地址:https://www.cnblogs.com/yaos/p/7084510.html
Copyright © 2011-2022 走看看