The Source for Java Technology Collaboration
User: Password:



Start New Message Post a Reply

Subject:  You could just do this in 8 lines of Java
Date:  2008-02-24 17:15:52
From:  alexprayle2
Response to: 38% have never heard of Scala? Don't you guys/gals browse dzone?


I've never tried Scala but you could just do this in 8 lines of Java and keep it readable and familiar:

public static int loveMatch(String name1, String name2, String compWord) {
int [] tally = new int[compWord.length()];
for (char c : (name1 + name2).toCharArray())
for (int t = 0; t < tally.length; t++)
if (c == compWord.charAt(t)) tally[t]++;
for (int i = tally.length - 1; i >= 0; i--)
for (int j = 0; j < i; j++)
tally[j] += tally[j + 1];
return tally[0] * 2;
}

...and the author shouldn't blame Java for his implementation not supporting "is"... what's that all about?

 Feed java.net RSS Feeds