If you want to count the letters in a word there's no need for the alphabet array and the nested loops. Java chars are an integer type, and the letters a-z are consecutive in UniCode, so all you need is

for (char c : word.toCharArray())  count[c - 'a']++;
iamthwee commented: nice point +14
Member Avatar for iamthwee

^^ All the above is correct. Again, you have to look at this objectively. You could have used my algorithm but you would have obtained NO points because you haven't used datastructures.

So perhaps it is a moot point. I'm pretty sure your teacher isn't probably aware of this elegant solution otherwise everyone would have turned it in.

In education, these things hardly matter. What matters is if you've used the techniques taught on the course. It doesn't even matter if your code works. What matters is if you have written clear, and organised code. As far as I'm concerned, you've ticked all those boxes so you can expect your A grade.

Of course, when you get into the real world these things matter. All this is learned from experience. Like you I began with a similar permute algorithm. It was only through lots of trial and error and googling that I discovered this elegant solution.

commented: Thank you for the encouragement :) Actually everyone had to choose a different project idea for themselves :P +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.