Здравствуйте коллеги.
Прошу помощи в решении
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 printStream = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(outputStream);
System.setOut(stream);
testString.printSomething();
String numbers = outputStream.toString();
System.setOut(printStream);
String[] strings = numbers.split(" ");
int a = Integer.parseInt(strings[0]);
int b = Integer.parseInt(String.valueOf(strings[2]));
int c = 0;
if(strings[1].equals("+")){
c = a+b;
}else if(strings[1].equals("-")){
c = a-b;
}else if(strings[1].equals("*")){
c = a*b;
}
int lastIndex = numbers.lastIndexOf("\r\n");
System.out.println(numbers.substring(0,lastIndex)+c);
}
public static class TestString {
public void printSomething() {
System.out.println("3 + 6 = ");
}
}
}