java - hi am trying converting two dimentional array into three single dimentional array -
hi trying converting 2 dimentional array 3 single dimentional arrays how dont know 1 knows please me
here array there
double[][] data= {{97, 36, 79}, {94, 74, 60}, {68, 76, 58}, {64, 87, 56}, {68, 27, 73}, {74, 99, 42}, {7, 93, 87}, {51, 69, 40}, {38, 23, 33}, {57, 86, 31}};
i want get:
double[] xarry={97,94,68,.....}//first elements double[] yarry={36,74,76,.....}//second elements double[] bubble_size={79,60,58,.....}//third element
code snippet:
for (int = 0; < bubble_data.length; i++) { if ( bubble_data[i][0]>0) count++; } x_array = new double[count]; int k = 0; (int = 0; < bubble_data.length; i++) { if ( bubble_data[i][0]>0) { x_array[k] = bubble_data[i]; k++; } }
it's not difficult, if have attempted yourself.
- get length of
data
array, create 3 1-d double arrays length. - traverse
data
array, put correct values in 1-d arrays using index 0-2
code:
public class quicktester { public static void main(string[] args) { double [][] data= {{97, 36, 79}, {94, 74, 60}, {68, 76, 58}, {64, 87, 56}, {68, 27, 73}, {74, 99, 42}, {7, 93, 87}, {51, 69, 40}, {38, 23, 33}, {57, 86, 31}}; double [] xarr = new double[data.length]; double [] yarr = new double[data.length]; double [] bubblesizearr = new double[data.length]; for(int = 0; < data.length; i++) { xarr[i] = data[i][0]; yarr[i] = data[i][1]; bubblesizearr[i] = data[i][2]; } // test printing for(int = 0; < data.length; i++) { system.out.printf("%5.2f %5.2f %5.2f%n", xarr[i], yarr[i], bubblesizearr[i]); } } }
output:
97.00 36.00 79.00 94.00 74.00 60.00 68.00 76.00 58.00 64.00 87.00 56.00 68.00 27.00 73.00 74.00 99.00 42.00 7.00 93.00 87.00 51.00 69.00 40.00 38.00 23.00 33.00 57.00 86.00 31.00
Comments
Post a Comment