Search This Blog

Saturday, November 20, 2010

Write a Java Program to Reverse a number

public class DoWhile{
  public static void main(String[] args){
    int n = 5678;
    int t,r = 0;
    System.out.println("Original No. : " + n);
    do{
      t = n % 10;
      r = r * 10 + t;
      n = n / 10;
    }while (n > 0);
    System.out.println("Reverse No. : " + r);
  }
}

1 comments:

Unknown said...

Very Useful. For more examples visit http://answersz.com

Post a Comment