Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ordenarNomes{
  3. public static void main(String[] args) {
  4. Scanner in = new Scanner(System.in);
  5. String [] nomes = new String [20];
  6.  
  7. for(int i=0;i<nomes.length;i++){
  8. System.out.println("Informe os nomes: ");
  9. nomes[i] = in.next();
  10. }
  11. String x = " ";
  12. for(int i=1;i<nomes.length-1;i++){
  13. for(int j=i+1;j<nomes.length;j++){
  14. if(nomes[i] > nomes[j]){
  15. x = nomes[i];
  16. nomes[i] = nomes[j];
  17. nomes[j] = x;
  18. }
  19. }
  20. }
  21. for(int i=0;i<nomes.length;i++){
  22. System.out.print(nomes[i]+" ");
  23. }
  24. }
  25. }
  26.  
  27. import java.util.Scanner;
  28.  
  29. class OrdenarNomes {
  30. public static void main(String[] args) {
  31. Scanner in = new Scanner(System.in);
  32. String[] nomes = new String[20];
  33. for (int i = 0; i < nomes.length; i++) {
  34. System.out.println("Informe os nomes: ");
  35. nomes[i] = in.next();
  36. }
  37. String x = " ";
  38. for (int i = 0; i < nomes.length - 1; i++) {
  39. for (int j = i + 1; j < nomes.length; j++) {
  40. if (nomes[i].compareTo(nomes[j]) > 0) {
  41. x = nomes[i];
  42. nomes[i] = nomes[j];
  43. nomes[j] = x;
  44. }
  45. }
  46. }
  47. for (int i = 0; i < nomes.length; i++) System.out.print(nomes[i]+" ");
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement