• Post Reply Bookmark Topic Watch Topic
  • New Topic

ASCII converter  RSS feed

 
Antoine Compagnie
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was ask, during a contest to build a decimal number to char converter in 5 minutes.
I didn't achieved it because it was row of three digits and I was only able to read them one by one

INPUT:
String of decimal numbers. Each number is 3 digits long and padded with zeroes.

OUTPUT:
The corresponding ASCII string.
If the input length is not a multiple of 3, then you should output the string ERROR.

CONSTRAINTS:
0 < Length of code ≤ 500
32 ≤ ASCII code ≤ 255

EXAMPLE:
Input
067111100105110103
Output
Coding


I did:



Which didn't achieved what I want.

How should I have handle such a problem? I'm okay with hints if you think I can progress from yhem.

Thanks in advance!
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at String class's substrting(), Integer class's parseInt and cast to char
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're supposed to check that the length of the code is a multiple of 3.

A for-loop doesn't have to be incremented by 1 all the time. You can have any increment size that you need.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Antoine Compagnie wrote:(...)
How should I have handle such a problem?

Given that your solution is incorrect, and that 5 minutes is really very short, I wonder:
- what kind of contest was this?
- what made you think you were up to such a contest?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!