Results 1 to 6 of 6
  1. #1
    jeffrey is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Default code and decode?

    hey guys.
    a simple help would do.
    on this problem, it asked to decode the number to a value.
    the problem here now is,
    how would you distinguish 1 and 4 from 14?
    please help me.


    Code and Decode.Create a program that asks for a value of n and generates a decoded version of the per value version of n. Use a do-while looping statement.

    Ex:
    Codes: a = 1; b = 2; c = 3; d = 4; e = 5; and so on
    n = 145
    output: ade

    Note:
    1) do not use more than 1 variable to get the list of number values (i.e., n)
    2) do not use arrays!
    3) you will be the one to define the coded version of the number values
    4) use only a single class and a single method, that's main()

  2. #2
    jeffrey is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Default

    anyone?
    who knows how to distinguish numbers?

    example would be

    input = 450

    and output would be for 45=A, 0=a
    so,
    Aa
    would be the result despite of the for 4 = e , 5 = d (eda)

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Quote Originally Posted by jeffrey View Post
    anyone?
    who knows how to distinguish numbers?

    example would be

    input = 450

    and output would be for 45=A, 0=a
    so,
    Aa
    would be the result despite of the for 4 = e , 5 = d (eda)
    As you've discovered the requirements are ill-defined, it would seem. As you say, there is no way to determine if the result should be Aa or eda. Go back to whoever came up with this and ask them to clarify.

    This, of course, assumes that there are more than ten letters to contend with.

  4. #4
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    i think you shoul use something like a sentinel value.

    for example if I was using it I would put them in a string. then use the Scanner to read it...
    since you can pass a string to a scanner.

    so for example if I have :
    1 2 3 14 ...
    "123/14"

    Here I just used '/' as the sentinel value.

  5. #5
    mleather is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default Don't try too hard

    Looking at the original post, it looks like we're thinking too hard.

    If the input is 450, then the output should be three digits as well. Just assign letters to 0 to 9 and then parse one number at a time. That means you only have letters assigned, but it would satisfy the notes at the top.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    You could be right, but I'd still go back and confirm the requirements and that they do only have to deal with 10 characters mapping to 0-9.

    I know it's an exercise, but this sort of ill-defined stuff comes up all the time in the real world and failure to clarify is one of the big causes of projects going badly wrong.

Similar Threads

  1. Getting problem in UTF-8 Encode/Decode with Java
    By sagarsway in forum Advanced Java
    Replies: 2
    Last Post: 12-22-2008, 07:01 PM
  2. allowable characters from URLDecoder.decode(String
    By Nicholas Jordan in forum Networking
    Replies: 4
    Last Post: 10-18-2008, 05:46 PM
  3. MimeUtility.decode encoding
    By mwildam in forum Advanced Java
    Replies: 2
    Last Post: 08-19-2008, 02:41 PM
  4. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 10:12 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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