DEV Community

hema latha
hema latha

Posted on

while loop programs Reverse No

package day1;

public class Reverse {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int no = 5678;

    int reverse = 0;
    while(no>0)
    {
        reverse = reverse*10 + no%10;
        no=no/10;


    }
    System.out.println(reverse); }}
Enter fullscreen mode Exit fullscreen mode

output= 8765

Top comments (0)