Guest User

Untitled

a guest
Jan 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // package whatever; // don't place package name!
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.lang.Math.*;
  6.  
  7. class MyCode {
  8. public static void main (String[] args) {
  9.  
  10. int input = 3579;
  11.  
  12. //convert to string
  13. String converted = Integer.toString(input);
  14. //sort it
  15. ArrayList<Character> convertedList = new ArrayList<Character>();
  16. for(int i =0; i < converted.length(); i ++){
  17. convertedList.add(converted.charAt(i));
  18. }
  19.  
  20. // convertedList.sort();
  21. Collections.sort(convertedList, Collections.reverseOrder());
  22.  
  23. // Iterator<Character> iter = convertedList.iterator();
  24.  
  25. // while(iter.hasNext()){
  26. // System.out.println(iter.next());
  27. // }
  28. //
  29.  
  30. //convert it to integer
  31. int n = convertedList.size();
  32. int exp = (int)Math.pow(10,n);
  33. //int result = 0;
  34. int i = 0;
  35. String result = "";
  36.  
  37. Iterator<Character> iter = convertedList.iterator();
  38. StringBuilder sb = new StringBuilder();
  39. while(iter.hasNext()){
  40. sb.append(iter.next());
  41. }
  42.  
  43. int k = Integer.parseInt(sb.toString());
  44.  
  45. System.out.println("Final: " + k);
  46.  
  47. }
  48.  
  49. }
Add Comment
Please, Sign In to add comment