Basically, I've got a value1, value2 and value3, which need to be the 3 largest values from an array. A friend and I have literally tried for hours to make a working method to create this, resulting in things like this (we're getting the values from a HashMap and put it in an array):
setStrings = randomHashMap.keySet();
String[] tempArray = (String[])setStrings.toArray(new String[20]);
String tempString = tempArray[index];
Integer test = (Integer)randomHashMap.get(tempString);
int a = test.intValue();
for(int index=0; index
String[] tempArray1 = (String[])setStrings1.toArray(new String[20]);
String tempString1 = tempArray1[index1];
Integer test1 = (Integer)randomHashMap.get(tempString1);
int b = test1.intValue();
if(a >= B){
if(a>value1){
if(value1>value2){
value2=value1;
}
else{
value3=value1;
}
value1 = a;
if(b>value2) {
if(value2>value3){
value2 = b;
}
else{
value3=value2;
value2 = b;
}
}
else{
if(value1>value2){
value2=value1;
}
else{
value3=value1;
}
value1=b;
}
Now I know the above method doesn't work. I've tried dozens of variants on this type of solution (also making a second loop, but I thought it should be possible to get the highest values from a list using only 1 value from the list).
Can anybody help? Me and my buddy are getting very tired and our solutions aren't becoming better.
Any help would be very appreciated!