string
Question:
WAP to accept a string and rewrite it in alphabetical order. e.g. COMPUTER --- > CEMOPRTU
💡 Solutions (1)
Super Admin
AdminFeb 09, 2026 at 07:35
upvotes
import java.util.Scanner; import java.util.Arrays; class AlphabeticalOrder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a string: "); String str = sc.nextLine(); // Convert string to character array char[] ch = str.toCharArray(); // Sort characters Arrays.sort(ch); // Convert back to string String result = new String(ch); System.out.println("Alphabetical order: " + result); sc.close(); } }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!