Valhalla Legends Archive

Programming => General Programming => Java Programming => Topic started by: Falcon[anti-yL] on October 14, 2004, 08:39 PM

Title: subString
Post by: Falcon[anti-yL] on October 14, 2004, 08:39 PM
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?
Title: Re: subString
Post by: The-FooL on October 14, 2004, 09:14 PM

Integer.toString(var).substring(...etc..)
Title: Re: subString
Post by: iago on October 15, 2004, 01:02 PM
There's actually a built-in class for converting a date to a java.util.Date.  But I can't remember what it is.
Title: Re: subString
Post by: MyndFyre on October 18, 2004, 06:48 PM
Quote from: iago on October 15, 2004, 01:02 PM
There's actually a built-in class for converting a date to a java.util.Date.  But I can't remember what it is.
DateFormat.parse(String) (http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html)
Title: Re: subString
Post by: CrAzY on October 18, 2004, 07:12 PM
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=='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.
Title: Re: subString
Post by: Falcon[anti-yL] on October 18, 2004, 07:21 PM
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.