There are two problems 1) Be sure that main(String[] args) method call System.SetOut() twice. But I did call twice.
2) Additional problems are not solved correctly. I can not locate them.
Thanks for your help.
package com.codegym.task.task19.task1914;
/*
Problem solving
*/
import java.io.*;
import java.util.*;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) throws IOException{
PrintStream consoleStream = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(outputStream);
System.setOut(stream);
testString.printSomething();
String result = consoleStream.toString();
StringBuilder sb = new StringBuilder(result);
String[] arr = result.split(" ");
int x = Integer.parseInt(arr[0]);
int y = Integer.parseInt(arr[2]);
switch (arr[1]) {
case "+":
sb.append(x + y);
break;
case "-":
sb.append(x - y);
break;
case "*":
sb.append(x * y);
break;
}
System.out.println(sb.toString());
System.setOut(consoleStream);
System.out.println(result);
}
public static class TestString {
public void printSomething() {
System.out.println("3 + 6 = ");
}
}
}