I tested it multiple times and it works fine, but the last condition is not met. Please help.
package com.codegym.task.task19.task1914;
/*
Problem solving
*/
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) {
PrintStream consoleStream = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(outputStream);
System.setOut(stream);
testString.printSomething();
System.setOut(consoleStream);
String result = outputStream.toString();
result = result.substring(0, result.length() - 2);
String[] chars = result.split(" ");
int number1 = Integer.parseInt(chars[0]);
int number2 = Integer.parseInt(chars[2]);
String operation = chars[1];
if (operation.equals("+"))
System.out.println(result + (number1 + number2));
else if (operation.equals("-"))
System.out.println(result + (number1 - number2));
else if (operation.equals("*"))
System.out.println(result + (number1 * number2));
}
public static class TestString {
public void printSomething() {
System.out.println("3 + 6 = ");
}
}
}