Computer Science Canada Tokenizer Help |
Author: | jamonathin [ Mon Dec 05, 2005 1:25 pm ] | ||
Post subject: | Tokenizer Help | ||
Hey all, this Friday is the computer science competition (Hikaru knows what im talkin bout) and my java skills are pretty poop. Unfortionately for me my c++ is much better and I didn't find out untill last week that we could of used c++ but there's a completely different way of compiling it, and changing would juss screw up my teammates. So, anyways, what I'm asking is this. There were some sample problems for us to try and some of them included Tokenizer. Now I understand how to get the "tokens" when there is a space inbetween and convert them to an integer but how about when the user inputs . .
All i've understood so far was how to grab those numbers, not how to extract them out of a string. How would i go about taking the '04', '21' and '90' out of that. And the input will always be in that same format ( dd/mm/yy ) pleh ![]() |
Author: | wtd [ Mon Dec 05, 2005 1:30 pm ] | ||
Post subject: | |||
Something this simple doesn't need any kind of special tokenizer class.
|
Author: | jamonathin [ Mon Dec 05, 2005 2:05 pm ] |
Post subject: | |
Ok, so basically i make a new array variable that will end up being three because the string is being split. Then i can assign the arrays to whatever var i want. Thanks wtd, looks simple enough ![]() |
Author: | jamonathin [ Mon Dec 05, 2005 2:14 pm ] |
Post subject: | |
Since you're so quick at responding wtd ![]() |
Author: | wtd [ Mon Dec 05, 2005 4:16 pm ] | ||||
Post subject: | |||||
|
Author: | Hikaru79 [ Tue Dec 06, 2005 8:36 am ] | ||
Post subject: | |||
Although wtd is right, you don't need a StringTokenizer for something like that, here's what it would have been if you'd chosen to do it.
The second, optional, argument is a String, of which every individual character is a delimiter. |
Author: | jamonathin [ Tue Dec 06, 2005 11:39 am ] |
Post subject: | |
Sounds good, thanks for your help wtd and hikaru |
Author: | jamonathin [ Tue Dec 06, 2005 11:59 am ] | ||||
Post subject: | |||||
wtd wrote:
Another question about that wtd. I tried using random symbols in my attempts at trying to find out the 'or' sign, and i tried using
inbetween my conditions and the program ran it, then I switched over to the " || ", and it produced the same thing. Is that ^ an or sign or what ![]() |
Author: | wtd [ Tue Dec 06, 2005 1:06 pm ] | ||||
Post subject: | |||||
jamonathin wrote: wtd wrote:
Another question about that wtd. I tried using random symbols in my attempts at trying to find out the 'or' sign, and i tried using
inbetween my conditions and the program ran it, then I switched over to the " || ", and it produced the same thing. Is that ^ an or sign or what ![]() http://java.sun.com/docs/books/tutorial/java/nutsandbolts/bitwise.html It's "bitwise exclusive or". |
Author: | 1of42 [ Tue Dec 06, 2005 6:30 pm ] | ||
Post subject: | |||
Hikaru79 wrote: Although wtd is right, you don't need a StringTokenizer for something like that, here's what it would have been if you'd chosen to do it.
The second, optional, argument is a String, of which every individual character is a delimiter. StringTokenizer is deprecated, don't even bother. |
Author: | jamonathin [ Wed Dec 07, 2005 1:37 pm ] | ||
Post subject: | |||
This goes with the long question I had for wtd. I think the code you gave me isn't for that long of numbers. When i try: 564696543201678654789456 in my program, i get erros, but smaller numbers are fine. Here's my code:
|
Author: | wtd [ Wed Dec 07, 2005 2:37 pm ] | ||
Post subject: | |||
A "long" is a 64-bit integer The largest number an unsigned 64-bit integer can hold is 18446744073709551615. Your number is larger than that, so you have problems.
|
Author: | jamonathin [ Wed Dec 07, 2005 2:49 pm ] |
Post subject: | |
Well then ****. . . lol. Because one of the questions we had to do was Problem 8: Extended Precision Addition wrote: Develop a program that takes as input two "long" nonnegative integers and outpus their sum. The inputs will be no longer than 35 digits. The program should repeat until the user enters zero for both inputs. Sample Program Execution: 1st input: 10371 2nd input: 315 Result: 10686 1st input: 54696543201678654789456 2nd input: 82067690004564356875434 Result: 136764233206243011664890 1st input: 0 2nd input: 0 Result: 0 What would I do if long wont take them ![]() |
Author: | wtd [ Wed Dec 07, 2005 2:53 pm ] |
Post subject: | |
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html |
Author: | Hikaru79 [ Wed Dec 07, 2005 11:33 pm ] | ||
Post subject: | |||
1of42 wrote: Hikaru79 wrote: Although wtd is right, you don't need a StringTokenizer for something like that, here's what it would have been if you'd chosen to do it.
The second, optional, argument is a String, of which every individual character is a delimiter. StringTokenizer is deprecated, don't even bother. Huh? How do you figure that? My JDK 1.5.0_4 doesn't seem to think it is (it will usually give you a warning if you're using deprecated objects) and the API ref at http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html doesn't say it is (it usually does). Where did you get the idea that such a useful thing is deprecated? |
Author: | wtd [ Wed Dec 07, 2005 11:34 pm ] |
Post subject: | |
I agree. I see no signs that it's deprecated. Though, in all honesty, the Scanner class may duplicate much of its functionality in a somewhat more convenient form. |
Author: | jamonathin [ Fri Dec 09, 2005 8:34 am ] | ||
Post subject: | |||
One last question. How would i do this. The user inputs a series of "things", and then the user enters some options of what could be in those things, and I have to check wether or not those things are in there. Such as . .
![]() |
Author: | wtd [ Fri Dec 09, 2005 9:48 am ] |
Post subject: | |
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html Check out the containsAll method |
Author: | jamonathin [ Fri Dec 09, 2005 10:45 am ] | ||||
Post subject: | |||||
Ok, easy enough, now how to I break up the second line. As in, how do i seperate the words. I know i have to go
and split it part by part, then i would go something like
then repeat for ( ")" ); . . but how can i look for the upper bounds of [i]hold?, or maybe there's an easier way ![]() |
Author: | jamonathin [ Fri Dec 09, 2005 10:47 am ] | ||
Post subject: | |||
(where's edit ![]()
|
Author: | wtd [ Fri Dec 09, 2005 11:09 am ] |
Post subject: | |
The input format is guaranteed? Is fo, then just "trim" off extra whitespace, remove the two parens, trim whitespace again, then split on: "\s*,\s*". |
Author: | jamonathin [ Fri Dec 09, 2005 12:05 pm ] |
Post subject: | |
Ok sounds good, thanx wtd ![]() |
Author: | wtd [ Fri Dec 09, 2005 2:47 pm ] |
Post subject: | |
wtd wrote: Is fo
Yay! I'm channeling Dan again. |