Hi It is a java problem array is 123456789 I want to write a
Hi!
It is a java problem.
array is {1,2,3,4,5,6,7,8,9} I want to write a java porgram to transfer to 3 x 3 matrix.
And, can you give me some example to solve n x n matrix??
For example, the input is {1,2,3,4,5,6,7,8,9,15,15,15,14,1,1,6} , how to tranfer to 4 x 4 matrix.
I need return like result[][]!! like result[3][3] or result[n][n]!!
Thanks!
the Array 1,2,3, 4,5,6,7,8,9Solution
We will start with the program:
-- We make the function name convertArrayToMatrix(); which takes 2 arguments. 1st being the array which we need to convert and 2nd is the dimension of the matrix.
Now we pass our array({1,2,3,4,5,6,7,8,9}) and n=3
This finally returns the matrix as:
We can similarly pass any array and any value of n(dimension of the array).
