Get the lowest value from Object[][]
Code :
public static Master generateMaster(Player player) {
Object[][] difference = new Object[7][7];
for (Master master : Master.values()) {
difference[master.ordinal()][0] = master;
difference[master.ordinal()][1] = player.getSkills().getCombatLevel() - master.getCombatLevel();
}
int lowest;
for (int i = 0; i < difference.length; i++) {
lowest = (int) difference[i][1];
if (((int) difference[i][1]) < lowest) {
lowest = (int) difference[i][1];
return (Master) difference[i][0];
}
}
return Master.VANNAKA;
}
The above is my code. What I'm wanting to do is get the lowest difference in difference[i][1] and return difference[i][0] once the lowest value is found.
Re: Get the lowest value from Object[][]
Can you show what your code does and explain what is wrong with the results?
You will need to post a small, complete program that compiles, executes and shows the problem for testing.
If you have any specific questions or problems, please ask.
Re: Get the lowest value from Object[][]
Quote:
Originally Posted by
Tyluur
...
The above is my code. What I'm wanting to do is get the lowest ...
A general method for your kind of task:
Code :
Declare two int variables: lowest and lowestIndx
Initialize the value of lowestIndex to 0
Initialize the value of lowest to the value from element 0 of the array.
Create a loop that looks at elements of the array, starting with an index value of 1
BEGIN LOOP
IF the array value using the current index value is less than lowest
THEN
Set lowest to the array value using the current index.
Set lowestIndx to the current index value.
END IF
END LOOP
//
// After the loop do whatever you want to do with the value of lowestIndx
//
Cheers!
Z