Tuesday, January 21, 2014

A function which will print in reverse order of a number.

//Write a java program which accepts
//an integer from command line argument
//and with a function which will print
//in reverse order as follow.

// java p502 345
// 543

class p502
{ public static void printReverse(int num)
  { while(num>0)
    { System.out.print(num%10);
      num/=10;
    }
  }
  public static void main(String args[])
  {  int n;
     n=Integer.parseInt(args[0]);
     printReverse(n);
  }
}

No comments:

Post a Comment