В 24 строке пишет, что синтаксически неверное выражение. Подскажите в чём подвох? потому что на мой взгляд решение верное
package com.javarush.task.task19.task1914;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
/*
Решаем пример
*/
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) {
PrintStream console = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut();
testString.printSomething();
System.setOut(console);
String[] str = outputStream.toString().split(" ");
int fn = Integer.parseInt(str[0]);
int ln = Integer.parseInt(str[2]);
int fl = switch (str[1].trim()) {
case "+" -> fn + ln;
case "-" -> fn - ln;
default -> fn * ln;
};
System.out.println(outputStream.toString().replace("\n", "") + fl);
}
public static class TestString {
public void printSomething() {
System.out.println("3 + 6 = ");
}
}
}
И почему setOut() пустой? Явно чего-то не хватает 😉