Java program to Reverse the given number

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);
	}
}

8 Responses to “Java program to Reverse the given number”

  1. shreyas

    when compiled sayas “exception in thread “main” java.lang.arrayindexoutofboundsexception:0 at Reverse.main “

    Reply
  2. sorry to say your source code is not usefull because the adds cover your code its not able to see your code.

    Reply
  3. Avas Ansuman

    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

    Reply
  4. siddesh

    shreya i think u wouldnt have passed the command line argument line.

    Reply
  5. prashanth

    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 :(

    Reply
  6. Jayashankar

    I want to reverse a number 1000 to 0001 can any one help me to find the solution.

    Reply

Leave a Reply