Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- g) Modifique o algoritmo de ordenação que trata das Provas, de modo a inserir um segundo critério de ordenação, o nome do aluno. Se dois alunos apresentam a mesma nota, use o nome para ordenar. Ordem crescente.
- String alunos[] = { "Maria", "Joanna", "Juliano", "Eduardo", "Regina", "Sirene", "Lucas", "Anna" };
- int vet[] = { 23, 44, 12, 18, 11, 19, 30, 25 };
- int i, j, posMaior;
- for (i = 0; i < vet.length; i++) {
- posMaior = 0;
- for (j = 0; j < vet.length - i; j++) {
- if (vet[posMaior] < vet[j]) {
- posMaior = j;
- }
- }
- int temp = vet[vet.length - i - 1];
- String sTemp = alunos[vet.length - i - 1];
- vet[vet.length - i - 1] = vet[posMaior];
- alunos[vet.length - i - 1] = alunos[posMaior];
- vet[posMaior] = temp;
- alunos[posMaior] = sTemp;
- }
- for (i = 0; i < vet.length; i++) {
- System.out.println(vet[i] + " - " + alunos[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement