• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

How Can i filter the tokens  RSS feed

 
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?.
*****************************
 
author
Sheriff
Posts: 23601
138
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
Sheriff
Posts: 23601
138
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 ]
 
author and iconoclast
Sheriff
Posts: 24220
40
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
Boost this thread!