Hello!
It is necessary to solve the following problem
Enter N lines. Arrange and display lines in ascending order of their length values. If the lengths of the lines are the same, sort them in lexicographical order.
Wrote code to arrange strings.
Question: how to implement the output of the same length of lines in a lexicographical order I can not understand.
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] + "\""); } }