Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // package whatever; // don't place package name!
- import java.io.*;
- import java.util.*;
- import java.lang.Math.*;
- class MyCode {
- public static void main (String[] args) {
- int input = 3579;
- //convert to string
- String converted = Integer.toString(input);
- //sort it
- ArrayList<Character> convertedList = new ArrayList<Character>();
- for(int i =0; i < converted.length(); i ++){
- convertedList.add(converted.charAt(i));
- }
- // convertedList.sort();
- Collections.sort(convertedList, Collections.reverseOrder());
- // Iterator<Character> iter = convertedList.iterator();
- // while(iter.hasNext()){
- // System.out.println(iter.next());
- // }
- //
- //convert it to integer
- int n = convertedList.size();
- int exp = (int)Math.pow(10,n);
- //int result = 0;
- int i = 0;
- String result = "";
- Iterator<Character> iter = convertedList.iterator();
- StringBuilder sb = new StringBuilder();
- while(iter.hasNext()){
- sb.append(iter.next());
- }
- int k = Integer.parseInt(sb.toString());
- System.out.println("Final: " + k);
- }
- }
Add Comment
Please, Sign In to add comment