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

2 comments:

Nataraja said...

very nice. for java examples, visit http://java2novice.com site

Answerz Answerz said...

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

Post a Comment