Java Reading Lines and Doing Math Equations -


so have project do, need read text file named input, , i'm doing this:

    public static void textparser() {     file inputfile = new file("input.txt");     try {         bufferedreader br = new bufferedreader(new filereader(inputfile));         string inputstext;         while ((inputstext = br.readline()) != null) {             system.out.println(inputstext);         }         br.close();     } catch (exception e) {         e.printstacktrace();     } } 

and works. inside of input.txt, shows:

6 10 + 4 12 - 3 1000 / 50 9 * 64 2^5 90 % 8 1 + 1 6 * 4 

the first line (6) amount of equations to-do, can different 6. have how many equations first line says to, how go on doing that? thanks!

you need write parser. without doing homework pseudo-code should sufficient:

for line in readfile()   {     token in split(line,expression)     {         if token digit            digits.enqueue(token)        if token symbol            symbols.enqueue(token)       }        element in digits,symbols:             applysymbol(firstdigit,seconddigit,symbol) }   

Comments