How could I pass the final condition?
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();
String result = outputStream.toString();
System.setOut(consoleStream);
if(result.contains("+")) {
String[] words = result.split("\\+");
double a = Double.parseDouble(words[0].replaceAll("\\=","").trim());
double b = Double.parseDouble(words[1].replaceAll("\\=","").trim());
long c = Math.round(a + b);
String end =result.substring(result.length()-2,result.length());
result = result.substring(0,result.length()-2) +c;
// result = result + end;
}
else if (result.contains("-")) {
String[] words = result.split("\\-");
int a = Integer.parseInt(words[0].replaceAll("\\D",""));
int b = Integer.parseInt(words[1].replaceAll("\\D",""));
long c = a-b;
result = result.substring(0,result.length()-2) +c+result.substring(result.length()-2,result.length());
}
else if (result.contains("*")) {
String[] words = result.split("\\*");
int a = Integer.parseInt(words[0].replaceAll("\\D",""));
int b = Integer.parseInt(words[1].replaceAll("\\D",""));
long c = a*b;
result = result.substring(0,result.length()-2) +c+result.substring(result.length()-2,result.length());
}
System.out.print(result);
}
public static class TestString {
public void printSomething() {
System.out.println("3 + 6 = ");
}
}
}