Advertisement
lukasw0001

letrag

Nov 12th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. 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.
  2.  
  3. String alunos[] = { "Maria", "Joanna", "Juliano", "Eduardo", "Regina", "Sirene", "Lucas", "Anna" };
  4. int vet[] = { 23, 44, 12, 18, 11, 19, 30, 25 };
  5. int i, j, posMaior;
  6. for (i = 0; i < vet.length; i++) {
  7. posMaior = 0;
  8. for (j = 0; j < vet.length - i; j++) {
  9. if (vet[posMaior] < vet[j]) {
  10. posMaior = j;
  11. }
  12. }
  13. int temp = vet[vet.length - i - 1];
  14. String sTemp = alunos[vet.length - i - 1];
  15. vet[vet.length - i - 1] = vet[posMaior];
  16. alunos[vet.length - i - 1] = alunos[posMaior];
  17. vet[posMaior] = temp;
  18. alunos[posMaior] = sTemp;
  19. }
  20. for (i = 0; i < vet.length; i++) {
  21. System.out.println(vet[i] + " - " + alunos[i]);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement