• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Can i filter the tokens

 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I want to filter a stream of numbers or char or what ever,

for example,
i have a program that prompt the user to write 6 digits
>1 2 3 4 5 6
then the program will filter the digits that don't contain 3, which is1,2, 4,5 and 6

iam trying with this code, but it never succeed


while (token.hasMoreTokens())
{
if((token.nextToken())!="3")
System.out.println(token.nextToken());
else ...
...
}

in the above code
it will check if the digit is not 3, then it will print the digit after. NOT THE CURRENT DIGIT
*************************
the Question is:-
how can i print the current digit
is there a way?.
*****************************
 
Henry Wong
author
Marshal
Pie
Posts: 21517
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the above code
it will check if the digit is not 3, then it will print the digit after. NOT THE CURRENT DIGIT
*************************
the Question is:-
how can i print the current digit
is there a way?.
*****************************


If you want to print the current digit, don't call nextToken() again. Use the token that you got in the "if" statement.

And BTW, you should be using the equals() method to compare the values of strings.

Henry
 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:


If you want to print the current digit, don't call nextToken() again. Use the token that you got in the "if" statement.

And BTW, you should be using the equals() method to compare the values of strings.

Henry


Thx Henry,
but this is my old question, How to print the token that i got from the if statement?.
there is no such method in StringTokenizer
What do you think about the Arrray??. Is it a possible solution?.

Regards
 
Henry Wong
author
Marshal
Pie
Posts: 21517
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes the most obvious solution is the correct solution. You are definitely "over thinking" the problem.

Henry


[ May 10, 2005: Message edited by: Henry Wong ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Class --

This is the second time I'm asking you to please change your display name to comply with our naming policy. To refresh your memory, that policy states that your display name must be a real (sounding) first and last name. I know you've already had some questions answered on JavaRanch -- I don't think it's to much for us to ask in return that you follow a few simple rules. Please take care of this right away.
 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Mr. Class --

This is the second time I'm asking you to please change your display name to comply with our naming policy. To refresh your memory, that policy states that your display name must be a real (sounding) first and last name. I know you've already had some questions answered on JavaRanch -- I don't think it's to much for us to ask in return that you follow a few simple rules. Please take care of this right away.



I'm very sorry Mr.Ernest Friedman-Hill, this is my 1st time i see this complaint from you.

please accept my apology,

best Regards

[ May 10, 2005: Message edited by: Moham'd ]
[ May 10, 2005: Message edited by: Moham'd ]
 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:
Sometimes the most obvious solution is the correct solution. You are definitely "over thinking" the problem.

Henry



[ May 10, 2005: Message edited by: Henry Wong ]



Thank you Mr. Henry for your support, it is working fine with me

Best Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic