import java.util.*; import java.io.*; import java.lang.*; public class magicnum{ public static void main(String args[]) throws java.util.NoSuchElementException { Scanner sc=new Scanner(System.in); System.out.println("Enter a string value: "); String st = sc.nextLine(); int j = 0; char temp = 0; char[] character = st.toCharArray(); for(int i=0; i < character.length; i++) { for(j=0; j < character.length; j++) { if(character[j] > character[i]) { temp = character[i]; character[i] = character[j]; character[j] = temp; } } } System.out.println("After Sorting:"); String str1=new String(character); System.out.println("Magic name is:"+str1); } }
Quote:Is there any way in which the same code can be written without using toCharArray()?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)