Results 1 to 6 of 6
Thread: code and decode?
- 08-04-2009, 07:50 AM #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?
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()
- 08-04-2009, 08:21 AM #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)
- 08-04-2009, 11:17 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 08-06-2009, 10:56 PM #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.
- 08-07-2009, 01:34 AM #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.
- 08-07-2009, 09:18 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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
-
Getting problem in UTF-8 Encode/Decode with Java
By sagarsway in forum Advanced JavaReplies: 2Last Post: 12-22-2008, 07:01 PM -
allowable characters from URLDecoder.decode(String
By Nicholas Jordan in forum NetworkingReplies: 4Last Post: 10-18-2008, 05:46 PM -
MimeUtility.decode encoding
By mwildam in forum Advanced JavaReplies: 2Last Post: 08-19-2008, 02:41 PM -
I need help fixing my code.. or non code?
By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 10:12 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks