Well, this is my first time get here.
I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.
First, convert letter to number. Second, restore number to word.
Words list: a = 1, b = 2, f = 6 and k = 11.
I have word: "baafk"
So, for first step, it must be: "211611"
Number "211611" must be converted to "baafk".
But, I failed at second step.
Code I've tried:
Result for converting to number: baafk = 211611public class str_number { public static void main(String[] args){ String word = "baafk"; String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11"); System.out.println(word); System.out.println(number); System.out.println(); String text = number.replace("11", "k").replace("6","f").replace("2","b").replace("1","a"); System.out.println(number); System.out.println(text); } }
But, result for converting above number to letter: 211611 = bkfk
What do I miss here?
How to distinguish if 11 is for "aa" and for "k"? Do you have any solutions or other ways for this case?
Thank you.


LinkBack URL
About LinkBacks
Reply With Quote