Advertisement
merlinaccio

Untitled

Jan 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8. // 30-OrdinaNomi ----------------------------------------------------
  9.  
  10. String matr[] = { "carlo", "anna", "jack", "paolo", "lucia", "chiara", "ste", "cris", "diego", "elisa" };
  11. System.out.println("Elenco non ordinato");
  12. for (int i = 0; i < matr.length; i++) {
  13. System.out.print(matr[i] + " ");
  14. }
  15. System.out.println("\n");
  16. System.out.println("Elenco ordinato");
  17. selectionSortStr(matr);
  18. }
  19.  
  20. // metodi
  21. // -------------------------------------------------------------------------
  22.  
  23. static int inputInt(String messaggio) {
  24. String s = JOptionPane.showInputDialog(messaggio);
  25. return Integer.parseInt(s);
  26. }
  27.  
  28. // metodo ordinamento ascendente -------------------------------------------
  29.  
  30. static void selectionSortStr(String[] a) {
  31. int min;
  32. String temp;
  33. int confr;
  34. for (int i = 0; i < a.length - 1; i++) {
  35. min = i;
  36. for (int j = i + 1; j < a.length; j++) {
  37. confr = a[min].compareTo(a[j]);
  38. if (confr <= 0) {
  39. min = j;
  40. }
  41. if (min != i) {
  42. temp = a[min];
  43. a[min] = a[i];
  44. a[i] = temp;
  45. }
  46. }
  47. }
  48. for (int i = 0; i < a.length; i++) {
  49. System.out.print(a[i] + " ");
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement