Question:
Gentlemen, good time of the day. Such a question: why, using Random, when outputting to the console, the matrix consists of some incomprehensible values (moreover, they are all the same), and when using the same Random for an ordinary number, the number is actually displayed, and not the "hashcode"
package ru.itpark;
import java.util.Random;
import java.util.Scanner;
public class Main {
static int array_NxM[][];
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
System.out.println("Введите размер матрицы");
System.out.print("Количество строк: ");
int n=in.nextInt();
System.out.print("Количество столбцов: ");
int m=in.nextInt();
array_NxM= new int [n][m];
Random random =new Random();
for (int i=0; i<n; i++){
for( int j=0; j<m; j++){
array_NxM[i][j]= random.nextInt();
}
}
for (int i=0; i<n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(array_NxM+" ");
}
System.out.println();
}
int b=random.nextInt();
System.out.println();
System.out.println(b);
}
}
Here's the output:
Введите размер матрицы
Количество строк: 5
Количество столбцов: 5
[[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858
[[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858
[[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858
[[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858
[[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858 [[I@6e0be858
1155286982
Answer:
Thank you Igor. I incorrectly displayed the array itself, it is necessary not
System.out.print(array_NxM+" ");
a:
System.out.print(array_NxM[i][j]);