public class Solution {
    public static void main(String[] args) throws IOException {
        if (args[0] == null) return;
        String tag = "<" + args[0];
        String tag2 = "</" + args[0] + ">";

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String filename = bufferedReader.readLine();
        bufferedReader.close();
        FileReader fileReader = new FileReader(filename);
        StringBuilder builder = new StringBuilder();
        while (fileReader.ready()) builder.append((char) fileReader.read());
        fileReader.close();


        String exemple = builder.toString();
        char[] thischar = exemple.toCharArray();

        ArrayList<String> tagresult = new ArrayList<>();
        int tagcount = 0;

        for (int i = 0; i < thischar.length; i++) {
            if (thischar[i] == '<' & (i + tag.length() < thischar.length)) {
                String temp = exemple.substring(i, i + tag.length());
                if (temp.equals(tag)) {
                    for (int c = i; c < thischar.length; c++) {
                        if (thischar[c] == '<' & (c + tag.length() < thischar.length)) {
                            temp = exemple.substring(c, c + tag.length());
                            if (temp.equals(tag)) tagcount++;
                        }
                        if (thischar[c] == '<' & (c + tag2.length() < thischar.length)) {
                            temp = exemple.substring(c, c + tag2.length());
                            if (temp.equals(tag2)) tagcount--;
                        }
                        if (tagcount == 0) {
                            String newTest = exemple.substring(i, c + tag2.length()).replaceAll("\\r\\n", "");
                            tagresult.add(newTest);
                            break;
                        }
                    }
                }
            }
        }
        tagresult.forEach(System.out::println);

    }
}
Собственно вопрос, что ему не нравится? вывод правильный, а валидатор не пускает.