Валидатор не принимает. Рекомендация от ментора: Внимательно проверь 'рекламный' текст, похоже ты допустил опечатку. Помогите!
package com.javarush.task.task19.task1927;
/*
Контекстная реклама
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) throws IOException {
PrintStream cons = System.out;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bos);
System.setOut(ps);
testString.printSomething();
String [] str = bos.toString().split(System.lineSeparator());
StringBuilder sb = new StringBuilder(bos.toString());
String context = "JavaRush - курсы Java онлайн" + System.lineSeparator();
for (int i = 0; i < str.length; i ++) {
if ((i + 1) % 2 == 0){
int index = sb.indexOf(str[i + 1]);
sb.insert(index, context);
}
}
bos.reset();
bos.write(sb.toString().getBytes());
System.setOut(cons);
ps.close();
System.out.println(bos);
}
public static class TestString {
public void printSomething() {
System.out.println("first");
System.out.println("second");
System.out.println("third");
System.out.println("fourth");
System.out.println("fifth");
}
}
}