Friday, June 29, 2018

Reverse the number !!

public class MathsSol {
    public static void main(String args[]) {
        int a = 4958;
        reverseNumber(a);
    }
    public static void reverseNumber(int num) {
        int remainder = 0;
        while (num != 0) {
            remainder = remainder * 10 + num % 10;
            num = num / 10;
        }
        System.out.println(remainder);
    }
}

Output:
8594

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...