Hello GTU students, this is a program in Java to reverse the digits of a number using while loop
public class ReverseNumberExample1
{
public static void main(String[] args)
{
int number = 654321, reverse = 0;
while(number != 0)
{
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number/10;
}
System.out.println("The reverse of the given digits is: " + reverse);
}
}
Output:
The reverse of the given digits is: 123456
follow me on instagram : https://www.instagram.com/sarjil_/
Comments
Post a Comment