Here we are using array to reverse a number in Java.
Code:
Number after reverse :
0543021
Code:
public class ReverseNumberA {
public static void main(String args[])
{
reverseNum(1203450);
}
public static void reverseNum(int num)
{
int length=String.valueOf(num).length();
int number[]=new int[length];
for(int n=0;n<=number.length-1;n++)
{
number[n]=num%10;
num=num/10;
}
System.out.println("Number after reverse :");
for(int n:number)
{
System.out.print(n);
}
}
}
Output:Number after reverse :
0543021
No comments:
Post a Comment