Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Reverse Number

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reverse Number

    Hello,

    i'm new to java programming and so i am having quite some difficulty with one particular problem. in this code i'm supposed to ask the user to enter an integer value. then using a while loop, i am supposed to display this integer value entered by the user but in reverse order. so, as an example if the user enters the number 54321 the completed program must display 12345. also, the completed program must treat both the number entered by the user, and the number it produces, as integer values. please keep in mind that so far in class we haven't learned anything beyond using conditional statements (if,else...) and loops (while, for...). also this program requires a while loop. any help would be appreciated.

    thank-you


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Reverse Number

    I'm guessing this is homework. What do you have so far?

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: Reverse Number

    how bout this as a starting for you

    1.) take the input value as a String first
    2.) reverse it using this code

    StringBuilder sb = new StringBuilder(<input value here>)
    String temp = sb.reverse().toString();

    3.) before displaying it make sure its a number first
    int parsedNumber = Integer.parseInt(temp);

    4.) then output

Similar Threads

  1. Replies: 5
    Last Post: April 22nd, 2013, 07:27 AM
  2. check if a number is an integer
    By rsala004 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 15th, 2009, 03:51 PM
  3. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM
  4. [SOLVED] How to string a decimal number in Java?
    By Lizard in forum Loops & Control Statements
    Replies: 6
    Last Post: May 14th, 2009, 03:59 PM
  5. [SOLVED] Random number method implementation
    By big_c in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2009, 01:10 PM