Write a java program to reverse a given number....... given number =24
Answers
Answered by
1
class reverse
{
public static void main(String args[ ] )
{
int n=24,rev=0,r;
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
System.out.println("Reverse of a Number " +rev);
}
}
Answered by
0
I have used the reverse() function
import java.util.Scanner;
public class NumberReverser {
int reverse = 0;
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
StringBuilder number = new StringBuilder(sc.next());
System.out.print("The reversed number is ");
System.out.print(number.reverse());
}
}
Output:
Enter a number: 123456789
The reversed number is 987654321
Similar questions