code and decode?
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.
Codes: a = 1; b = 2; c = 3; d = 4; e = 5; and so on
n = 145
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()
who knows how to distinguish numbers?
example would be
input = 450
and output would be for 45=A, 0=a
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.
Originally Posted by jeffrey
This, of course, assumes that there are more than ten letters to contend with.
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 ...
Here I just used '/' as the sentinel value.
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.
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.