Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public static void task2() throws IOException {
  2. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  3. int n = Integer.parseInt(reader.readLine());
  4. String[] strings = new String[n];
  5.  
  6. //Считываем строки
  7. for (int i = 0; i < strings.length; i++) {
  8. strings[i] = reader.readLine();
  9. }
  10.  
  11. //Сортировка массива методом пузырька
  12. for (int i = strings.length - 1; i > 0; i--) {
  13. for (int j = 0; j < i; j++) {
  14. if (strings[j].length() > strings[j + 1].length()) {
  15. String max = strings[j];
  16. strings[j] = strings[j + 1];
  17. strings[j + 1] = max;
  18. }
  19. }
  20. }
  21. //Вывод элементов массива
  22. for (int i = 0; i < strings.length; i++) {
  23. System.out.println("(" + strings[i].length() + ")" + ":" + " " + """ + strings[i] + """);
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement