Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to separate string token by white space

$
0
0
	public static MathExpression getUserInput(){
		int amount;
		String expression;
		MathExpression []userAmount;
		System.out.println("How many math expressions did you want to enter?");
		amount = scanner.nextInt();
		if(amount <= 0)
			amount = 1;
		userAmount = new MathExpression[amount];
		System.out.println("Enter your expression:");
		expression = scanner.nextLine();
		
		
		
		return userAmount[amount];
	}



Here is what I am trying to do:
Read a prefix expression into a String (to the end of line) in which each token is separated by white spaces.

I'm not quite sure how to do this. Do I enforce that the user enters the prefix expression in such a way, or do I modify the expression to be formatted this way?

The next part that I must do is:
Create a StringTokenizer using the input string (default delimiters).

Which I believe should be coded something like this:
StringTokenizer str = new StringTokenizer(expression); 


But I'm not entirely sure of this either.

Thank you for your time!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>