Write a java program to Reversing a Number

Write a program to read a positive number as input and to get the reverse of the given number and return it as output.

The return type is an integer value which is the reverse of the given number.

Input and Output Format:

Input consists of a positive integer.

The output is an integer.

Refer sample output for formatting specifications.

Sample Input 1:

543

Sample Output 1:

345

Sample Input 2:

1111

Sample Output 2:

1111

Reverse a Number in Java.

import java.util.Scanner;

public class Main {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int number= sc.nextInt();
int d=number,rev=0,rem=0;
while(d!=0)
{
rem=d%10;
rev=rev*10+rem;
d=d/10;
}
System.out.println(rev);

}
}

Add a Comment

Your email address will not be published. Required fields are marked *

five × 3 =