Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void task2() throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int n = Integer.parseInt(reader.readLine());
- String[] strings = new String[n];
- //Считываем строки
- for (int i = 0; i < strings.length; i++) {
- strings[i] = reader.readLine();
- }
- //Сортировка массива методом пузырька
- for (int i = strings.length - 1; i > 0; i--) {
- for (int j = 0; j < i; j++) {
- if (strings[j].length() > strings[j + 1].length()) {
- String max = strings[j];
- strings[j] = strings[j + 1];
- strings[j + 1] = max;
- }
- }
- }
- //Вывод элементов массива
- for (int i = 0; i < strings.length; i++) {
- System.out.println("(" + strings[i].length() + ")" + ":" + " " + """ + strings[i] + """);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement