I'm not sure what techniques you can use to parse the String: "1, 2, and 3." and find the numeric digits that are to be replaced with text without looping.
switch statements are a way to "jump" to a block of code based on a value. Some think it a cleaner way to code than to use if/else if statements.
Can you use recursive methods? They can do things similar to looping.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
I'm not sure what techniques you can use to parse the String: "1, 2, and 3." and find the numeric digits that are to be replaced with text without looping.
switch statements are a way to "jump" to a block of code based on a value. Some think it a cleaner way to code than to use if/else if statements.
Can you use recursive methods? They can do things similar to looping.
Hmm yes i do agree with Norm... maybe you could take the string entered and convert to a char array via toCharArray(), then make an integer counter equal to 0, and the use an if statement to see when the value reaches the arrays size by charArrayName.length, call the method to check each char for a digit by isDigit() (the method should accept one char and return a string of the char using switch)and repeat this for the entire length of the array and dont forget to increment your counter used to call the method
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
I did receive a hint from my TA, this is what he told me: If you are unfamiliar with switch, you may recall from the last class that it is used to set off case statements for handling certain input cases. If you want your append method to be flexible and handle arguments of different return types, use overloading. Remember what happens if you try to compare strings using the == comparative operator.
I'm not sure if we can use recursion. We haven't gone over that yet in class.
well yes you cant compare a string using '==' only primitive values... so checking StringName==null would still hold true, but not StringName=="test". to test strings for comparison use equals() method
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
The switch statement can be replaced with if/else if statements that will do almost exactly the same thing.
To scan the contents of a String, you need a loop.
It is conceivable to write a program as if and else statements to cover all the possible combinations, but it would be huge, like a tree with many many many branches.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
How do you get the char values from the String, skipping over the "," the "and" and the "."
and how do you call the method with each value that is found in the String
without a loop?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
So this was all a big waste of time. The parsing of the String is done by code that is not shown.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656