Wednesday, 11 September 2013

How to process and parse a string from user input

How to process and parse a string from user input

For example, an user entered a string "a + a = b". The program needs to
find two numbers, one for each unique letter, to make the string true. And
let's assume we already have had an algorithm to enumerate all possible
combinations of number zero to nine. However, for example, when the
program wants to test if 0 and 1 can be solutions for a and b, how do I
translate the string "a + a = b" to some java code that can be used to
test if 0 + 0 = 1 (when a = 0, b = 1)? To deal with the string, I know I
need to extract the plus and equal sign and translate the letter to
number(maybe?). But if the input is "abc + bc = def". I need a way to know
how many letters there are before or after the plus sign and equal sign. I
hope this is not too confusing. Thanks!

No comments:

Post a Comment