/********** 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 */
Subscribe to:
Post Comments (Atom)
the output shud be 021 aite?
tested it, it's stil 012.. aahhh.
I have made some changes .. just check n let me know.
Thank u !!
Thank u
for(i=0;i<s;i++)
{
System.out.print(no[i]);
}
this will make it work
this will give correct answer
for(i=0;i<s;i++)
{
System.out.print(no[i]);
}
sorry to say this.. i didnt get the correct answer for your program....
Sorry to say this... i cant answer for your program..
Sorry to say this... i cant get answer for your program..
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]);
}
Good one. here is another way to reverse digits of a number in Java