You are here:

Java/reversing a number using a while loop

Advertisement


Nishant Chaudhary wrote at 2013-08-23 20:32:47
class ReverseNumber

{

  public static void main(String[] args)

  {

     int number=12345;

     int rev=0;

     while(number>0)

     {

        rev=rev*10+number%10;

        

        number =number/10;



        

  }

  System.out.println(rev);

  }

}




Java

All Answers


Answers by Expert:


Ask Experts

Volunteer


Artemus Harper

Expertise

I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.

Experience

I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Organizations
Washington State University

Education/Credentials
MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 About.com. All rights reserved.