 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can print reverse of a particular number in Java. So for implementation purpose, first I am going to import a package whose name is util. Inside this package, a class is available that is scanner. I will be using this scanner class for reading values from user. Now I am going to define a class whose name is reverse. Inside this reverse class, I am going to implement main function definition. Now inside this main function, I am going to implement code which will receive a number from user and print its reverse. So I have declared three variables, num, reverse and tam. Now I am going to create instance of scanner class whose name is input and I am passing system.in as constructor parameter for this scanner class, which will decide that the input will be received from console. Now I am going to print a message and enter a number on output screen with the help of system.out.println. The entered number will be stored in num variable and that will be done with the help of next int method which is defined in scanner class. So to use this next int method, I have imported scanner class. Now I am going to implement the logic for making reverse of this num variable value. Now I am implementing while loop. Condition will be num greater than zero. So this loop will repeat if num is greater than zero, if num is equals to or less than zero, then this loop will be terminated. Now first I am going to calculate value of tam using this formula num modulus 10. So whenever we divide a particular number with 10, we always find out its remainder that is last digit. So last digit will be stored inside tam variable. Now I am applying another statement reverse equals to reverse into 10 plus tam and I am initializing reverse with zero. So initially reverse is zero. It will be multiplied with 10 so it will remain zero and the value which is available in tam will be added into reverse and then num equals to num by 10. So this is the logic to calculate reverse. Now I am taking an example. Suppose number is 1, 2, 3. So first we have to calculate this expression tam equals to num modulus 10. So number is 123. I am dividing it by 10. So remainder will be 3. So value of tam is now 3. Then we have to calculate value of reverse. So initially it is zero. Zero into 10 is zero. Now tam is added into reverse. So reverse will also become 3. Now num is divided by 10. So new value of num will be 12. So whenever we divide a particular number by 10, its last value will be removed automatically. Now we have to check the condition of loop num greater than zero. So current value of num is 12. So condition is true. This time here at line number 13, num is 12. So 12 modulus 10. So new value of tam will be 2. Here at line number 14, current value of reverse is 3. So 3 will be multiplied with 10. So it will become 30 and tam is 2. So new value of reverse will become 32. And here line number 15, num will be again divided by 10. So instead of 12, it will be now 1. Again, we have to check the condition of loop at line number 11. So condition is true. This time value of num is 1. So 1 modulus 10 is equals to 1. Current value of reverse is 32. So 32 into 10, 320 plus tam. Tam is 1. So reverse will become 321. And at line number 15, 1 by 10, which will become 0. So current value of num is 0. Now again check condition of line number 11. It is now false. So it means loop will be terminated. And you can see the value of reverse. It is 321, which is the reverse of num that is 123. I hope you have understood the iteration of this while loop early now. After completion of loop with the help of system.out.println, I can print the reverse on output screen. So this is the complete implementation of the program. I have saved this program in D drive inside Java folder with reverse.java name. Now after implementation, I have to compile this code. I am moving to D drive. Then inside Java folder. So right now my current location is the Java. Now I am going to compile the program for this. I have typed Java C reverse dot Java. If there are any errors in the code, it will be displayed. Otherwise program will be compiled successfully. So in our case program is compiled successfully. Now I can execute this code. It is asking for a number. I am entering 4567. It is a four digit number. You can see the result. It is printing 7654, which is the reverse of 4567. So this program is generic for any number of digits. Any number of digits means the range of int. If you exceed the range of int, then the garbage value will be displayed. So then you have to take another data type like long, or you can say float or double if you want to exceed the range. But in this case, you can print reverse of 2, 3, 4, 5, 6 digit numbers. So I hope you have understood how we can print reverse of a particular number in Java with the help of Y loop. If you want to watch more programming related videos, you can follow my YouTube channel. Thank you for watching this video.