I have given here Java code for Kaprekar Transformation for a 3 digit number. The logic is as follows:
1. Make sure the given number is 3 digits.
2. Make sure all the digits are not same.
3. With the given number, form two numbers with descending and ascending 3 digits.
4. Subtract the small number from the big number.
5. Take the difference as a new number and repeat step 3 until you reach 495.
Source code can be found at http://www.softwareandfinance.com/Java/Kaprekar_transformation_3digit_number.html