[java]class Reverse{
public static void main(String args[]){
int num = Integer.parseInt(args[0]); //take argument as command line
int remainder, result=0;
while(num>0){
remainder = num%10;
result = result * 10 + remainder;
num = num/10;
}
System.out.println("Reverse number is : "+result);
}
}
[/java]
sorry to say your source code is not usefull because the adds cover your code its not able to see your code.
class reverse
{
public void main(int a)
{
int b=a/1000
int c=a%1000
int d=c/100
int e=c%100
int f=e/10
int g=e%10
int a1=1000*g+100*f+10*d+b
System.out.println(a1);
}
}
i think the integer a1 will have many memory allocation units in contrast to integer a which i think has only one units.IWOULD BE GRATEFUL TO YOU IF U READ THIS AND REPLY WHAT IS MY MISTAKE.
REGARDS
shreya i think u wouldnt have passed the command line argument line.
use “try catch” block
class Sha{
public static void main(String[] args){
int n=1234,reverse=0;
System.out.println(“Enter your number to reverse”);
while(n<1){
reverse = reverse*10;
reverse = reverse+n%10;
n = n/10;
}
System.out.println("Reverse number is =" +n);
}
}
getting output as same 🙁
I want to reverse a number 1000 to 0001 can any one help me to find the solution.