Introduction: Because when using matrix to perform calculations, the one-dimensional array will first be converted into a two-dimensional array. Therefore, I will record it here, and I hope it will be helpful to others.
Example code:
package deal;public class ArryTest {public static void main(String[] args) {//Create a one-dimensional array 0,1,2,3...,10double [] c= new double[10];for (int i = 0; i < c.length; i++) {c[i]=i;}double[][] testArr=TwoArry(c);for (int i = 0; i < testArr.length; i++) {for (int j = 0; j < testArr[i].length; j++) {System.out.println(testArr[i][j]);}}}//Convert one-dimensional array into two-dimensional array public static double[][] TwoArry(double[] onedouble){double[][] arr=new double[1][onedouble.length];for (int i = 0; i < onedouble.length; i++) {arr[0][i]=onedouble[i];}return arr;}}Running results:
Summarize
The above is all the content of this article about converting a one-dimensional array into a two-dimensional array instance code for Java programming. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!