Please see my code below, in the last two lines of my code that is ArrayList<Float> minList = minsMap.get(minC);
and minList.add(itemElement);
, I am facing issue. In the first line when value of minC
is zero that is minC = 0
then in the second line zero is added to the list instead the value of itemElement
. In itemElement i have no zero. Please help me figure out what's wrong with this code.
public class absol
{
public static void main(String[] args)
{
float item[] = {7,4,8,5,6,65,45,33,8,6,3,98};
final float[][] arrayTwoD = { {3.5f, 4.55f, 2.1f, 1.40f},
{0.5f, 1.55f, 0.90f, 1.59f},
{4.5f, 5.55f, 3.1f, 2.4f},
{1.5f, 2.55f, 0.10f, 0.60f},
{2.5f, 3.55f, 1.10f, 0.40f},
{61.5f, 62.55f, 60.1f, 59.4f},
{41.5f, 42.55f, 40.1f, 39.4f},
{29.5f, 30.55f, 28.1f, 27.4f},
{4.5f, 5.55f, 3.1f, 2.4f},
{2.5f, 3.55f, 1.10f, 0.40f},
{0.5f, 0.55f, 1.90f, 2.6f},
{94.5f, 95.55f, 93.1f, 92.4f},
};
Map<Integer, ArrayList<Float>> minsMap = new LinkedHashMap<>();
// Initializing Map
for(int i=0; i<arrayTwoD[0].length; i++)
{
ArrayList<Float> minList =new ArrayList<>();
minList.add(0.0f);
minsMap.put(i, minList);
}
for(int row=0; row < arrayTwoD.length; row++)
{
float min = arrayTwoD[row][0];
int minC = 0;
float itemElement =0;
for(int col=0; col < arrayTwoD[row].length; col++)
{
if(arrayTwoD[row][col] < min)
{
min = arrayTwoD[row][col];
itemElement = item[row];
minC = col;
}
}
ArrayList<Float> minList = minsMap.get(minC);
minList.add(itemElement);
}
// for(int i= 0; i< minsMap.size(); i++)
// {
// System.out.print("\n\t Values in List "+i);
// for(int j= 0; j< minsMap.get(i).size(); j++)
// {
// System.out.print("\t"+minsMap.get(i).get(j)); //////////////////////////////
// }
// }
}
}