не вижу в упор, в чем проблема. протестил до пятизначных чисел, выводит все верно)
и самое главное, оба сетАута присутствуют =/
package com.javarush.task.task19.task1914;
/*
Решаем пример
*/
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) {
PrintStream consoleStream = System.out;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteArrayOutputStream);
System.setOut(printStream); //<======== setOut
testString.printSomething();
String result = byteArrayOutputStream.toString();
Pattern pattern = Pattern.compile("^(\\d+)\\s(\\+|\\-|\\*)\\s(\\d+).+$");
Matcher matcher = pattern.matcher(result);
int i1 = Integer.parseInt(matcher.group(1));
int i2 = Integer.parseInt(matcher.group(3));
int resultInt = 0;
if(matcher.group(2).equals("+")) resultInt = i1 + i2;
if(matcher.group(2).equals("-")) resultInt = i1 - i2;
if(matcher.group(2).equals("*")) resultInt = i1 * i2;
System.setOut(consoleStream); //<========== setOut
System.out.printf("%d %s %d = %d", i1, matcher.group(2), i2, resultInt);
}
public static class TestString {
public void printSomething() {
System.out.print("3 + 6 = ");
}
}
}