import java.util.Scanner; public class Task1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of strings: "); int n = scanner.nextInt(); scanner.nextLine(); // Consume the newline String[] strings = new String[n]; System.out.println("Enter the strings:"); for (int i = 0; i < n; i++) { strings[i] = scanner.nextLine(); } // Bubble sort using compareTo() for (int i = 0; i < strings.length - 1; i++) { for (int j = 0; j < strings.length - i - 1; j++) { if (strings[j].compareTo(strings[j + 1]) > 0) { // Swap strings[j] and strings[j + 1] String temp = strings[j]; strings[j] = strings[j + 1]; strings[j + 1] = temp; } } } // Print the sorted array System.out.println("Sorted Strings:"); for (String str : strings) { System.out.println(str); } scanner.close(); } }