void (String text) { int xCnt = 0, yCnt = 0; int pos = text.length() - 1; for (; pos >= 0; --pos) { char ch = text.charAt(pos); if (ch == 'X' || ch == 'x') ++xCnt; else if (ch == 'Y' || ch == 'y') ++yCnt; else if (Character.isDigit(ch)) { ++pos; break; } } text = text.substring(0, pos); if (<warning descr="Condition 'text.length() == 0' is always 'false'">text.length() == 0</warning>) { throw new IllegalArgumentException(); } System.out.println(xCnt + ":" + yCnt); }