File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes count of operands Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "count of operands" Watch "count of operands" New topic

count of operands


Joined: Aug 26, 2002
Posts: 10
I wrote a code to count the number of operators and operands in a file. I was able to calculate the count of operators, but stuck at the operands. Do i need to use hasNextToken() method, or something else. Please Help this novice.
Thank you,
Kishore Kumar Bokkala
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Please post your code, using the *code* tags, thanks.

Please ignore post, I have no idea what I am talking about.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I can imagine a couple of different solutions - one using a StringTokenizer that would use the operators as the delimiters, and one using regular expressions. Do you have any ideas?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This approach won't work; have a look at the expression 'x+a- -b' (note the space character). Simply checking for '+' and/or '-' tokens in the sequence isn't gonna help you; are we talking three operands here? three operators and four operands in total? I think the original question has to be rephrased a bit before a reasonable answer can be given ...
kind regards
Ranch Hand

Joined: Jul 15, 2002
Posts: 53
Hi kishore...
Plz post ur code...

Thank you,<br />Sanju
I agree. Here's the link:
subject: count of operands
It's not a secret anymore!