The following code is available:

private void massiveGet() { i = Integer.parseInt(elemNumbers.getText()); int count = 0; while (count < i) { count++; int number = (int) (Math.random() * 100); matrixData.add(new Massive(number)); } System.out.println(matrixData); } 

It is necessary to fill the Observable List collection according to the entered number i , say, the number 5 is entered, the collection is filled in as a matrix 5 * 5

  • ... the question is what? - Alexey Shimansky
  • so what algorithm? can't understand - Mishustiq
  • So that the observatory list will fill up with 5 * 5 and I only have 5 - Mishustiq
  • one
    What is your Massive class? Why does his constructor accept only one number? - diraria
  • Class array is a pojo model with getters / setters - Mishustiq

1 answer 1

If I understand the question correctly, then you do not have a matrix, but the same number of values, which is specified because your cycle works i the number of times, so that the matrix would be necessary to pass the square of the required value in the cycle condition. Your option:

 i = Integer.parseInt(elemNumbers.getText()); int count = 0; while (count < i) { 

those. if i = 5 it will work 5 times. here it is necessary either before the condition of the cycle to multiply the transmitted number by i * = i; those.:

 i = Integer.parseInt(elemNumbers.getText()); int count = 0; i *= i; while (count < i) { 

either implemented in 2 cycles:

 class example { int count; private void massiveGet() { count = Integer.parseInt(elemNumbers.getText()); for (int i = 0; i < count; i++) { for(int k = 0; k < count; k++){ int number = (int) (Math.random() * 100); matrixData.add(new Massive(number)); } //Здесь можно организовать перенос строки в матрице } System.out.println(matrixData); } } 

In my opinion, the second option is more convenient, from the point of view that, if necessary, you can reset certain values ​​during a "line break".