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 7 of 7

Thread: reversing number without using while

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

    Default reversing number without using while

    Hello guys, i have to write a program which deals with reversing number and i need to solve it without using the while statement.
    the program conditions is to get a number from the user between 100 and 999 and the first digit of the number and the last digit of the
    number, can't be the same.
    and my task is to reverse that number, but without using the "while" statement.
    e.g. "reverse the number 486" ------> the reversed number is 684.

    Thank you all!

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: reversing number without using while

    Do you have a specific question? And you haven't shown what you have done thus far.

    Regards,
    Jim

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: reversing number without using while

    i do have a specific question but its irrelevant, i just need to know if there is any possibility to reverse a number without using the while statement

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: reversing number without using while

    Yes! And I am assuming it's not just a while statement but using any loop at all (e.g. a for loop).

    Regards,
    Jim

  5. #5
    Junior Member
    Join Date
    Oct 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: reversing number without using while

    i meant, can't i solve this with just with division and the modulo sign?

  6. #6
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: reversing number without using while

    Yes. That is one way to do it. But let me throw in a snag. If you have the number 290 do you need to show 092 or just 92? Leading zeroes in an integer are ignored upon printout so that would be need to taken care of depending on the requirement.

    Regards,
    Jim

  7. #7
    Junior Member
    Join Date
    Oct 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: reversing number without using while

    no, i need to reverse the whole number, zero is allowed to be the first digit e.g. 250---->025

Similar Threads

  1. Reversing a String
    By hkfrenchtoast in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 16th, 2014, 03:17 AM
  2. Reversing an Array
    By georger55 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 8th, 2012, 07:22 AM
  3. Do Loop, Reversing a Number Example, Incorrect Code in Book?
    By djl1990 in forum Loops & Control Statements
    Replies: 3
    Last Post: October 24th, 2011, 07:01 AM
  4. Reversing an array
    By severus1 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 30th, 2011, 03:54 PM
  5. Reversing lines using LinkedList
    By velop in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 14th, 2011, 05:10 AM

Tags for this Thread