Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

count of operands  RSS feed

 
Kishore
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code, using the *code* tags, thanks.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanju
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kishore...
Plz post ur code...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!