public class sort_string { public static void main(String[] args) { int j,temp=0; //String result = ""; System.out.println("enter string\n"); Scanner kbd = new Scanner(System.in); String input = kbd.nextLine(); char[] arr=input.toCharArray(); int count = 0; int [] intArray = new int[arr.length]; for (char i : arr) { int m = Character.getNumericValue(i); intArray[count] = m; count += 1; } int len=intArray.length; boolean swapped; for (int i = 0; i < len - 1; i++) { swapped = false; for (j = 0; j < len - i - 1; j++) { if(intArray[j] < intArray[j + 1]) { temp = intArray[j]; intArray[j] = intArray[j + 1]; intArray[j + 1] = temp; swapped = true; } } // IF no two elements were // swapped by inner loop, then break if (swapped == false) break; } for(int a:intArray) System.out.println(a); //String str=Arrays.toString(intArray); } }
Integer.toString(int)
String.valueOf(int)
//String str; String str = ""; for (int a:intArray) str += Integer.toString(a);
String str=intArray.toString();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)