Please admins, have a look at the code. It is printing to console exactly as per task conditions still it does not pass. The same is happening in many other questions. It is getting a bit frustrating.
package com.codegym.task.task19.task1927;
/*
Contextual advertising
*/
import java.io.*;
import java.util.*;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) {
PrintStream console = System.out;
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(os);
System.setOut(stream);
testString.printSomething();
System.setOut(console);
String s = os.toString();
String[] arr = s.split("\n");
int count = 0;
for(int i=0;i<arr.length;i++ ){
if(count == 2){
System.out.println("CodeGym - online Java courses");
count = 0;
i--;
}
else {
System.out.println(arr[i]);
count++;
}
}
}
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");
}
}
}