Reverse Of A Number

11 comments - Post a comment

/********** Java Program To Print Reverse Of A Number ************/

class Reverse
{
public static void main(String args[])
{
int i,s=0,a = 120;
int no[] = new int[10];
System.out.print("Original Number : "+a);
for(i=0;i< 10;i++)
{
if(a!= '\0')
{
no[i] = a%10;
a = a / 10;
s++;
}
else break;
}
System.out.print("\n\nReversed Number : ");
for(i=s;i>0;i--)
{
System.out.print(no[i]);
}
}
}
/************ OUTPUT ************
* Original Number : 120

* Reversed Number : 021 */

 
This Post has 11 Comments Add your own!
MarDeeYa - August 12, 2009 at 11:40 PM

the output shud be 021 aite?
tested it, it's stil 012.. aahhh.

Lionel - August 13, 2009 at 9:47 AM

I have made some changes .. just check n let me know.

soumya - July 26, 2010 at 12:32 PM

Thank u !!

soumya - July 26, 2010 at 12:33 PM

Thank u

Adivasi - October 22, 2010 at 11:32 PM

for(i=0;i<s;i++)
{
System.out.print(no[i]);
}

this will make it work

sarath - November 11, 2010 at 12:02 PM

this will give correct answer

for(i=0;i<s;i++)
{
System.out.print(no[i]);
}

poorani - December 8, 2010 at 4:06 PM

sorry to say this.. i didnt get the correct answer for your program....

poorani - December 8, 2010 at 4:07 PM

Sorry to say this... i cant answer for your program..

poorani - December 8, 2010 at 4:08 PM

Sorry to say this... i cant get answer for your program..

omkar - January 13, 2012 at 6:48 PM

no need to run for loop in reverse order ..for loop is the only change in the program

for(i=0;i<s;i++)
{
System.out.print(no[i]);
}

Java ArrayList size - April 24, 2012 at 9:52 AM

Good one. here is another way to reverse digits of a number in Java

Post a Comment