multiple strings in java
Question:
WAP to accept multiple strings and arrange them in ascending order
💡 Solutions (1)
Super Admin
AdminFeb 09, 2026 at 07:24
upvotes
//WAP to accept multiple strings and arrange them in ascending order import java.util.Scanner; import java.util.Arrays; class StringSort { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter number of strings: "); int n = sc.nextInt(); sc.nextLine(); // clear buffer String[] arr = new String[n]; System.out.println("Enter strings:"); for (int i = 0; i < n; i++) { arr[i] = sc.nextLine(); } // Sorting strings in ascending order Arrays.sort(arr); System.out.println("\nStrings in ascending order:"); for (String s : arr) { System.out.println(s); } sc.close(); } }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!