Results 1 to 4 of 4
  1. #1
    meghana.ck is offline Member
    Join Date
    Nov 2015
    Posts
    2
    Rep Power
    0

    Default Convert Integer into String

    Hi All,

    I am new to JAVA. I am working on one assignment given by my mentor.

    Requirement:

    1) Convert Integer to String.

    Ex1: 234: Two Hundred Thirty Four

    Ex2: 1456: One Thousand Four Hundred Fifty Six

    Could you please help me.

    Regards.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Convert Integer into String

    What have you tried? Did your mentor give you any clues? Do you have to work with the int value or can you convert it to a String?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    meghana.ck is offline Member
    Join Date
    Nov 2015
    Posts
    2
    Rep Power
    0

    Default Re: Convert Integer into String

    Hi,

    I wrote the logic to convert the numbers into Strings.

    Ex: If User gives 5 as input, Output should be FIVE.

    I wrote very cumbersome logic as mentioned below.

    1) First Find out the length of the Value

    2) If the length is 1, it is either ONE or TWO and so on till NINE

    3) If the length is 2, hard coded values from ELEVEN to NINETEEN

    4) Now I am writing logic to write the text for values greater than 21.

    Regards.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Convert Integer into String

    Sounds like you are making progress. Some of the code will have to be hand tailored for the numbers like 10 to 19.
    Above 19 you should be able to use an array that holds the names like Twenty, Thirty etc and then use the digits value to index into the array.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Help: Convert String to Integer
    By Firer44 in forum Advanced Java
    Replies: 14
    Last Post: 05-29-2014, 10:07 PM
  2. Replies: 6
    Last Post: 09-14-2012, 12:33 PM
  3. How to convert integer to String
    By mCoder in forum New To Java
    Replies: 2
    Last Post: 12-27-2011, 04:00 AM
  4. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  5. how to convert a string to an integer
    By LAW in forum New To Java
    Replies: 6
    Last Post: 11-09-2009, 03:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •