How to play around digits in java

Easy way — Java solution