FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 201   



Java program to to reverse a given number. Ex. If the input is 123 it prints 321


import java.util.Scanner;

public class ReverseNumber {
    public static void main(String args[]) {

        int input;
        int result = 0;

        System.out.println("Please enter a number");

        Scanner in = new Scanner(System.in);
        input = in.nextInt();
        in.close();

        while (input != 0) {
            result = result * 10;
            result = result + input % 10;
            input = input / 10;
        }

        System.out.println("Reverse of the given number is: " + result);
    }

}

Output:

Please enter a number
34
Reverse of the given number is: 43



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News