Добрый день,
Можно пример с которым не будет работать или подсказать в чем ошибка ?
П.С. Шёл 6 день...
package com.javarush.task.task19.task1918;
/*
Знакомство с тегами
*/
import java.io.*;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//FileReader fileReader = new FileReader("C:\\test\\1918.html");String teg = "span";
FileReader fileReader = new FileReader(reader.readLine());String teg = args[0];
reader.close();
String startTeg = '<' + teg;
String endTeg = '/' + teg + '>';
String txt = "";
while (fileReader.ready()){
txt += (char)fileReader.read();
}
fileReader.close();
String[] txtSplits = txt.split("<");
int ending = 0;
int starting = -200;
for (int i = 0; i<txtSplits.length; i++){
String txtSplit = txtSplits[i];
try {
if (txtSplit.substring(0,teg.length()+1).matches(teg+"[^A-Za-z0-9]")&& ending ==1) {
System.out.print("<" + txtSplit);
ending++;
starting = i-1;
}else if (txtSplit.substring(0,teg.length()+1).matches(teg+"[^A-Za-z0-9]")) {
System.out.print("<"+txtSplit);
ending++;
}else if(ending ==1 && txtSplit.endsWith(endTeg)){
System.out.println("<"+txtSplit);
ending=0;
if(starting != -200)
i = starting;
starting = -200;
}else if(ending !=0 && txtSplit.endsWith(endTeg)){
System.out.print("<"+txtSplit);
ending--;
}else if (ending !=0){
System.out.print("<"+txtSplit);
}
}catch (StringIndexOutOfBoundsException e){
if (ending !=0){
System.out.print("<"+txtSplit);
}
}
}
}
}