Personal notes
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
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