6
I have a HashMap aluno<Integer, Float>
, where the key Integer
will be the student’s registration number, and the amount Float
will be the student’s grade.
I got the grade average using the Iterator
, but now I need to know which students have the above average grade and I couldn’t do using the symbol >
follows the code:
HashMap<Integer, Float> aluno = new HashMap<Integer Float>();
.
.
.
//achei soma das notas
Iterator<Integer> i = aluno.keySet().iterator();
while(i.hasNext()){
int chave = i.next();
sumNotas+=aluno.get(chave);
}
//printei média
//n é a quantidde de alunos
System.out.println("média: " + sumNotas/n + "\n" + "Alunos acima da média:" + "\n");
//quero printar se a nota do aluno é maior que a média, mas não funciona
//n é a quantidde de alunos
while(i.hasNext()){
int chave = i.next();
if(aluno.get(chave) > sumNotas/n)
System.out.print(chave + ", ");
}
You have to start the iterator again because in the second while the iterator is at the end of Hasmap
– Jorge B.
@Jorgeb. already makes an answer
– Math
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero