Everything works fine and matches the example but the testing fails:
public static void main(String[] args) {
PrintStream backup = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
System.setOut(printStream);
new TestString().printSomething();
String result = outputStream.toString();
System.setOut(backup);
StringBuilder sb = new StringBuilder(result);
while (sb.indexOf("te") != -1) sb.replace(sb.indexOf("te"), sb.indexOf("te") + 2, "??");
String replacedString = sb.toString();
System.out.println(replacedString);
}
public static class TestString {
public void printSomething() {
System.out.println("This is text for testing");
}
}
package com.codegym.task.task19.task1912;
/*
Reader Wrapper 2
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) {
PrintStream backup = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
System.setOut(printStream);
new TestString().printSomething();
String result = outputStream.toString();
System.setOut(backup);
// StringBuilder sb = new StringBuilder(result);
// while (sb.indexOf("te") != -1) sb.replace(sb.indexOf("te"), sb.indexOf("te") + 2, "??");
result = result.replaceAll("te", "??");
// String replacedString = sb.toString();
System.out.println(result);
}
public static class TestString {
public void printSomething() {
System.out.println("This is text for testing");
}
}
}