[JAVA] Note: Assigning and displaying values to multidimensional arrays, and practicing extended for statements

Overview

Until now, when dealing with arrays of two dimensions or less, I somehow organized my head with images like tables or matrices. However, as soon as it became three-dimensional, it developed into a situation where the head completely bugged.

Therefore, [Beginners can understand] How to use Java multidimensional array and [Expand multidimensional array with extended for statement](http: / /java-lab.com/array-multidimensional-enhanced_for/), I reorganized my mind. The following is the program used for organizing.

Intdealing.java


public class Intdealing{
	public static void main(String[] args){
		int[][] nums = new int[3][4];
		
		System.out.printf("Number of rooms on the 0th floor:%d\n",nums.length);
		System.out.printf("Number of rooms on one floor:%d×%d\n",nums.length,nums[0].length);
		
		
		int[][][] nums2 = new int[8][18][2];
		
		System.out.printf("Number of rooms on the 0th floor:%d\n",nums2.length);
		System.out.printf("Number of rooms on one floor%d×%d\n",nums2.length,nums2[0].length);
		System.out.printf("Number of rooms on 2 floors%d×%d×%d\n",nums2.length,nums2[0].length,nums2[0][0].length);
		
		//Assign value using element number
		for(int i=0; i<nums2.length; i++){
			for(int j=0; j<nums2[i].length; j++){
					nums2[i][j][0] = 2*i;
					nums2[i][j][1] = 2*j;
			
			}
		}
		
		//Display values using extended for statement
		for(int[][] dimension1 : nums2){
			for(int[] dimension2 : dimension1){
				for(int dimension3 : dimension2){
					System.out.println(dimension3);
				}
			}
		}
	}
}

Digression

I spent about 4 hours going around the sites and managed to complete the program. Now, in my mind, a multidimensional array is seen as a series of vertically connected and stacked rooms, like an ant's nest or an apartment.

As I study the program, I feel that there are the most stumbling patterns like this one. I'm not sure if it's wrong to capture it as an image in the first place, or if it's the wrong image to capture ...

Recommended Posts

Note: Assigning and displaying values to multidimensional arrays, and practicing extended for statements
Difficult to handle minimum values for Java8 LocalDateTime and Java6 Date
Introduction to batch files (for statements, arrays, deferred environment variables)
Java while and for statements
Note No. 1 "Counting and displaying duplicate values in an array" [Java]
Utilization of Java array elements, for, length, value, and extended for statements
Until you understand that the extended for statement and the for statement using length are the same process (handle multidimensional arrays)