Valhalla Legends Forums Archive | Java Programming | subString

AuthorMessageTime
LW-Falcon
I'm writing a program that tells you what day you were born on. I want to input the year in 4 digits, then check to see if its before 1900. If its not, I want to take the last 2 digits out of the 4 digits. I know there was a subString for Strings but is there a way to do it for Integers?
October 15, 2004, 1:39 AM
The-FooL
[code]
Integer.toString(var).substring(...etc..)
[/code]
October 15, 2004, 2:14 AM
iago
There's actually a built-in class for converting a date to a java.util.Date.  But I can't remember what it is.
October 15, 2004, 6:02 PM
Myndfyr
[quote author=iago link=topic=9162.msg84571#msg84571 date=1097863337]
There's actually a built-in class for converting a date to a java.util.Date.  But I can't remember what it is.
[/quote]
DateFormat.parse(String)
October 18, 2004, 11:48 PM
CrAzY
I don't think this is the easiest way to do it but it should work if done correctly.

Make your substring, to get the last 2 digits.  now with that substring, use the toCharArray() method.  Then basically make a converter if char[i]=='1' { int = 1

I didn't make that TOO clear at all, but if you get what I'm saying, you should get it.

Please post an easier way if you know one somebody.
October 19, 2004, 12:12 AM
LW-Falcon
I got mine to work, I just basically stored the input 2 times, one as a string and the other as a string.
I don't know the toCharArray() method yet, I'm still learning.
October 19, 2004, 12:21 AM

Search