-4

If i input 1324,3591

It mean i want the bigger denote in order.

int x = 1324;
int y = 3591;
System.out.println(x+y);

I want the output show:

4321 and 8531

int num = x; 
char[] digits = Integer.toString(num).toCharArray();
Arrays.sort(digits); 


 System.out.println(digits);
      }

but i want use %04d to make output be 4 digit but if i change to prinf it can't run....

leppie
  • 115,091
  • 17
  • 196
  • 297
kappa
  • 11
  • 1
  • 5
  • Printing the sum wouldn't print that anyways. – Anindya Dutta Nov 27 '15 at 17:18
  • You asked [this **same** question yesterday](http://stackoverflow.com/questions/33943843/how-to-let-my-output-be-decreasing-and-increasing-order-in-digitjava). Please don't do duplicates of your questions! Instead *edit* your original question! – Frakcool Nov 27 '15 at 19:41

1 Answers1

0

You could just sort the number based on their digits.

int num = 1234; //suppose.
char[] digits = (""+num).toCharArray();
Arrays.sort(digits);
System.out.println(new StringBuilder().append(digits).reverse());
Anindya Dutta
  • 1,972
  • 2
  • 18
  • 33