簡(jiǎn)介:由于經(jīng)常在使用矩陣進(jìn)行計(jì)算時(shí),會(huì)首先將一維數(shù)組轉(zhuǎn)為二維數(shù)組。因此,在這里記錄一下,也希望對(duì)他人有幫助。
實(shí)例代碼:
package deal; public class ArryTest { public static void main(String[] args) { //創(chuàng)建一個(gè)一維數(shù)組 0,1,2,3...,10 double [] 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]); } } } //一維數(shù)組轉(zhuǎn)化為二維數(shù)組 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; } }