Two-dimensional array by just starting to study Java

Personal notes

It will not be helpful ~

Let's think about a two-dimensional array only with the knowledge that we have while touching Java

This time, a random number from 1 to 5 was inserted and displayed in a 2-dimensional array of 5 rows and 5 columns.

What I did </ b> Declaration of a two-dimensional array     ↓ Substitute random elements from 1 to 5     ↓ Repeat displaying with line breaks 5 times Like


package sample;

public class sample {

	public static void main(String[] args) {

		String sep = System.lineSeparator();

		int x = 6;
		int y = 6;

		int[][] array = new int [x][y];

		for(int i = 1; i < x; i++){
			for(int j = 1; j < y; j++){
				array[i][j] = new java.util.Random().nextInt(5)+1;
				System.out.print(array[i][j]);
			}
			System.out.print(sep);
		}

	}

}


The output looks like this

53232
31333
24344
34225
12133

Impressions

What is this childish code! !! It's like that. It seems that there are useful collections such as lists and randoms when I look it up. There is something like import java.util. ~; on the outside of the class, and it's really what it is, so I thought I'd study it one by one. (Study how to write Qiita ...) Next time, I will write a two-dimensional array containing random elements that do not overlap next to each other while considering the search algorithm etc. ^

Recommended Posts

Two-dimensional array by just starting to study Java
[Java ~ Array ~] Study memo 4
[Java] Convert ArrayList to array
How to initialize Java array
How to study Java Silver SE 8
[Java] Conversion from array to List
How to make a Java array
[Java] Convert array to ArrayList * Caution
[Java] array
Java array
java (array)
Java array
[Java] Array
[Java] How to turn a two-dimensional array with an extended for statement
"I'm sure it's good to study Java"
Java array
java array
[Java] Array
How to get and study java SE8 Gold
What Java inexperienced people did to study Kotlin
java array variable
Let's study Java
[Java] Array notes
[Java] Study notes
Ruby two-dimensional array
Java 8 study (repeatable)
Java study memorandum
Introduction to java
Study Java Silver 1
How to create a Java environment in just 3 seconds
[Java] How to get a request by HTTP communication
Comparative study of TLS Cipher Suite supported by Java 8
[Java] How to cut out a character string character by character
How to convert a file to a byte array in Java
[Java] Platforms to choose from for Java development starting now (2020)
Gzip-compress byte array in Java and output to file