package formula;
import java.io.IOException;
import java.io.InputStreamReader;
public class Formula {
public static void main(String[] args) throws IOException{
System.out.println("Введите формулу: ");
Formula f = new FormulaA();
int res = f.parseFormulaA();
System.out.println("результат: " + res);
}
InputStreamReader isr;
FormulaA(){
isr = new InputStreamReader(System.in);
}
int parseFormula() throws IOException {
int sym = isr.read();
if (sym != -1){
char ch = (char)sym;
if (Character.isDigit(ch)){
return Character.digit(ch, 10);
}
int left = parseFormula() ;
ch = (char)isr.read();
int right = parseFormula();
int result;
switch(ch){
case '+': result = left + right; break;
case '-': result = left - right; break;
default:
result = left * right; break;
}
ch = (char)isr.read();
return result;
}
return 0;
}
}
Можно ли использовать такую вот вещь: InputStreamReader isr1 = new InputStreamReader("input.txt"); ?