Guest User

Untitled

a guest
Feb 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package j1.s.p0001;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author Ak47pc
  14. */
  15. public class J1SP0001 {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21. bubble();
  22.  
  23. }
  24.  
  25. public static void bubble() {
  26. int sum = 0;
  27. ArrayList<String> obj = new ArrayList<String>();
  28. Scanner sc = new Scanner(System.in);
  29. System.out.println("Enter number of Array: ");
  30. String ip = sc.next();
  31. try {
  32. for (int i = 0; i < Integer.parseInt(ip); i++) {
  33. obj.add(sc.next());
  34. sum += 1;
  35. }
  36. } catch (Exception e) {
  37. System.out.println("Please input a number!");
  38. }
  39.  
  40. System.out.println(obj);
  41.  
  42.  
  43. }
  44.  
  45. }
  46.  
  47. public class Sort{
  48. private static ArrayList<String> list = new ArrayList<String>();
  49.  
  50. public static ArrayList<String> sortByName(String [] input) {
  51. String temp;
  52. for (int i=0; i< input.length; i++){
  53. for(int j= i; j< input.length-1; j++){
  54. char first = input[i].charAt(0);
  55. char sec = input[j +1].charAt(0);
  56. if (first < sec) {
  57. temp = input[j +1];
  58. input[j +1] = input[i];
  59. input[i] = temp;
  60. }
  61. }
  62. list.add(input[i]);
  63. }
  64.  
  65. return list;
  66. }
  67.  
  68. public static void main(String[] args) {
  69. String string[] = {"XXX", "YYY" , "ZZZ", "QQQ", "AAA"};
  70. bubbleSortByName(string);
  71. }
  72. }
Add Comment
Please, Sign In to add comment