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?
Integer.toString(var).substring(...etc..)
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 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)
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.
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.