I have got my result based on below approach, but I'm not satisfied.
I want some other way and efficient manner to get the expected output.
Input:
112341
Output:
1234
No duplicates should be displayed in output and answer must be 1234.
My solution :
public class PrintUnique {
public static void main(String[] args) {
int result = printUniquNums(112341);
System.out.println(result);
}
private static int printUniquNums(int num) {
String nums = Integer.toString(num);
char [] ch = nums.toCharArray();
Set<Character> store = new LinkedHashSet<>();
String res = "";
for (int i = 0; i < ch.length; i++){
if (store.add(ch[i])){
res += ch[i];
}
}
return Integer.parseInt(res);
}
}