A few things on readability:
First codeblock:
I would have the counters counting in the same direction– it will still compare each word this way. It’s not a terribly important change, but it can save the reader a step so that they don’t have to do any mental math to determine if the code is producing the intended result, since the result is apparent (it’s easy to see that the code’s time complexity is O(n^2)).
boolean isIsogram = true;
Scanner scanner = new Scanner(System.in);
String string = scanner.next();
long start = System.currentTimeMillis();
char words[] = string.toCharArray();
for (int i = 0 ; i <= words.length - 1; i++){
for(int j = 0; j <= words.length - 1; j++){
if(words[i] == words[j]){
isIsogram = false;
break; //I agree with the first answer
}
}
if (!isIsogram)
break;
}
long finish = System.currentTimeMillis();
System.out.println(isIsogram + " time:" + (finish-start) );
The second codeblock is quite readable, although I may be primed towards understanding the problem and so it might actually be more readable because of that. But the calls to compare distinct characters make complete sense in terms of the goal.
solved Which solution is better, faster and readable? [closed]