1. Member
Join Date
Jul 2009
Posts
7
Rep Power
0

## 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?

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

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. Member
Join Date
Jul 2009
Posts
7
Rep Power
0
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. Moderator
Join Date
Apr 2009
Posts
13,321
Rep Power
23
Originally Posted by jeffrey
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. Senior Member
Join Date
Jan 2009
Posts
119
Rep Power
0
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. Member
Join Date
Aug 2009
Posts
2
Rep Power
0

## 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. Moderator
Join Date
Apr 2009
Posts
13,321
Rep Power
23
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.

#### Posting Permissions

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