import java.util.*;
public class ReverseNo {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter Number which you want to reverse:");
int num = scan.nextInt();
int revNo = reverseNumber(num);
System.out.println("Reverse No:" + revNo);
}
public static int reverseNumber(int num) {
int revNo = 0;
while (num > 0) {
revNo = revNo * 10 + num % 10;
num = num / 10;
}
return revNo;
}
}
Labels:
Java
public class ReverseNo {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter Number which you want to reverse:");
int num = scan.nextInt();
int revNo = reverseNumber(num);
System.out.println("Reverse No:" + revNo);
}
public static int reverseNumber(int num) {
int revNo = 0;
while (num > 0) {
revNo = revNo * 10 + num % 10;
num = num / 10;
}
return revNo;
}
}
Responses
0 Respones to "36. Given a number, write a program using while loop to reverse the digits of the number."
Post a Comment