Perfectly balanced - Programming Challenge [Java]
There was a challenge, it goes like this: "Given a string containing only the characters x and y , find whether there are the same number of x s and y s." This is what I did: // Given a string containing only the characters x and y, find whether there // are the same number of x's and y's. public boolean balanced(String s) { int x = 0, y = 0; for (int i = 0; i < s.length(); i++) if (s.charAt(i) == 'x') x++; else if (s.charAt(i) == 'y') y++; if (x == y) return true; ...