View Single Post
  #1 (permalink)  
Old 07-31-2007, 07:38 PM
trill trill is offline
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
Help with string token
Hi, I need to make a program that has the user enter an expression and solve the expression from left to right ignoring any order of operations.
For example the expression: 2+5*2 = 14. I have everything done except for the solving of the expression. I dont know how to break up the inputed string. I know i need to use the string tokenizer but im not sure how.
Can someone help point me in a direction.
Here is what i have now:

Code:
import java.util.*; import java.io.*; public class Calc { //prompts the user for input and calls necessary methods public static void main(String args[]) { String cont = ""; do { System.out.println("Please enter a numeric expression."); Calc.getInput(); System.out.print("Do you want to enter another expression? (y/n): "); cont = Calc.getInput(); }while(cont.equalsIgnoreCase("y")); System.out.println("Goodbye"); } //gets a single input from the user, and returns it as a String static String getInput() { java.io.InputStreamReader input = new java.io.InputStreamReader(System.in); java.io.BufferedReader console = new java.io.BufferedReader(input); try { return console.readLine(); } catch(java.io.IOException e) { System.err.println("Bad NEWS!!!"); return ""; } } }
Thanks.
Reply With Quote
Sponsored Links