java - Finding the smallest min in and placing them in an array -
i working on method takes 2d array , find min value in each row. after find min in row, want go array. have array made, keep getting nulls in array. easy fix, i've been looking @ long, need help.
public static double[][] largearray; public static double[] minarray; public static double min; private static void min() { ( int row=0; row < largearray.length; row++) { min = largearray[row][0]; for(int col = 1; col > largearray[row].length; col++) { if ( largearray[row][col] < min ) min = largearray[row][col]; for(int t=0; t<minarray.length; t++) { min = minarray[row]; } } } }
thank looking @ this!
you aren't storing min
value(s) in minarray
. can use math.min(double, double)
in loop. finally, want <
(not >
) in inner loop condition , use arrays.tostring(double[])
display minarray
when have finished initializing it. like,
private static void min() { minarray = new double[largearray.length]; // <-- initialize array (int row = 0; row < largearray.length; row++) { min = largearray[row][0]; (int col = 1; col < largearray[row].length; col++) { min = math.min(min, largearray[row][col]); } minarray[row] = min; } system.out.println(arrays.tostring(minarray)); }
Comments
Post a Comment