This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have to do a numerology program for my Java class. The program takes as input the user's birthdate and name. The date has to be in mm/dd/yy format. Then we are supposed to break down the number, adding the digits of the date together, until it is a single digit, i.e., between 0 and 9. My question is: what is the best way to do the conversion from String to individual ints? Or should I break the String down into constituent Strings? Someone suggested I do that, and then copy them into an array. I am not sure of the best way to do this. Basically, I just want to take a date, like 11/03/78 and add the individual numbers together, reducing them to one number, like this: 1 + 1 + 0 + 3 + 7 + 8 = 20 = 2 + 0 = 2
I had a similar problem except with time instead of date. I could find no shortcut, so I did it manually. The only thing I can think of to do is to parse the string up into individual characters. Then use the Wrapper classes to convert the string representations of the numbers into actual ints. Then you can add them normally.
Michael J Bruesch<br /><i>I code, therefore I am.</i>
Joined: Oct 12, 2001
Is it better to use the wrapper classes than to break up the string and then cast to an int? I admit I am confused about how they are different. I know the wrapper classes are for converting primitive types to objects.