Толи лыжи не едут, толи я ........
Посмотрите пожалуйста что не так?
Рекомендиция от ментрора:
Примеры на сложение решаются неверно.
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 consoleStream = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(outputStream);
System.setOut(stream);
testString.printSomething();
String result = outputStream.toString();
System.setOut(consoleStream);
int firstDigit = 0;
int secondDigit = 0;
int res = 0;
//Удаляем все пробелы в строке
String resultMod = result.replaceAll(" ", "");
//Вылавливаем все числа из строки
for (String s : resultMod.split("\\W")) {
if (firstDigit == 0){
firstDigit = Integer.parseInt(s);
}else secondDigit = Integer.parseInt(s);
}
//Находим знак
String sing = result.replaceAll("[^[+][-][*]]", "");
if (sing.equals("+")){
res = firstDigit + secondDigit;
}else if (sing.equals("-")){
res = firstDigit - secondDigit;
}else if (sing.equals("*")){
res = firstDigit * secondDigit;
}
System.out.println(result + String.valueOf(res));
}
public static class TestString {
public void printSomething() {
System.out.print("3 + 6 = ");
}
}
}