-2

For the assignment, I need to solve verbal arithmetic puzzle with java (ex. send + more = money, base + ball = games)

I need some help for some part.

I can't explain exactly but I have no idea how to separate letters from string and save number variable in the letter. I used

    String word1 = "send";
    String word2 = "more";
    String word3 = "money";

in the send + more = money, letter every m's answer is 1. like this, I need to figure out every letter's answer from those words. However, I don't know how to separate those letters, find same letter, and save number in letter. (ex. letter m = 1, so every m should be 1. Therefore, I need search for m from every strings, and save number 1 in letter m. same process for every letter. )

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
Konorika
  • 69
  • 2
  • 9
  • 1
    Use [`indexOf()`](http://www.tutorialspoint.com/java/java_string_indexof.htm) for searching letters and [`Map`](http://docs.oracle.com/javase/7/docs/api/java/util/Map.html) for storing letter-digit association. – torvin Sep 23 '15 at 23:52
  • The way you're phrasing your question is very confusing; please clarify. Do you want to count how many times a letter appears in a `String`? – Michael Sep 23 '15 at 23:53
  • @Michael https://en.wikipedia.org/wiki/Verbal_arithmetic this would be help to understand my question. I want to do exactly samething in this page. It's my mistake didn't mention I want to verbal arithmetic – Konorika Sep 23 '15 at 23:56
  • Do you have a general idea about how you're going to solve it? – Cinnam Sep 24 '15 at 01:20

1 Answers1

0

Perhaps set each letter m to 1, like this:

String[] words = new String[3];
words[0] = "send";
words[1] = "more";
words[2] = "money";

for (int i = 0; i < words.length; i++) {
  words[i] = words[i].replaceAll("m", "1");
}

And afterward parsing each String as an integer. Is this what you are trying to do, or where you are getting stuck?

17slim
  • 1,233
  • 1
  • 16
  • 21