I have this algorithm:
NE= Integer.parseInt(JOptionPane.showInputDialog(null,"Digite numero de estudiantes"));
int j[]= new int [NE];
for (int k = 0; k < NE; k++) {
j[k] = Integer.parseInt(JOptionPane.showInputDialog(null,"Digite nota del estudiante "+(k+1)));
if (j[k]>NM) {
NM = j[k];
}else{
NMI = j[k];
}
}
for (int k = 0; k < NE; k++) {
JOptionPane.showMessageDialog(null,"La mas alta es: "+NM+" esta en la posición:"+j[k]+"\n"+
"La nota mas baja es: "+NMI+" esta en la posición: "+j[k]);
}
The algorithm shows me the desired notes, but it doesn't show me the position in which they are.
Your algorithm is wrong. It doesn't do what you say.
Note that the if verifies if the note just entered is greater than the one that was listed as greater... if so, it sets it as greater...
The problem is the else... if it is not greater, it is not necessarily the lesser...
Note that if you enter values like this:
You have 9 as the largest... and 5 as the smallest... when it should be 4 ;)
It's not if...else what you need...it's two if...
And then... when you look for the position in the vector, it is to go through the vector and compare...
Here... you should compare if j[k] is equal to NM or NMI, and show the corresponding poster ;)
Notice, that to show the position, you show k, not j[k]