For this program the user is told to input a data in the form of "mm/dd/yyyy" and I'm trying to use the indexOf() method with the parameter of "/" to break the date string into three substrings.
I tried doing this:
String monthString = dateString.substring(0,dateString.indexOf("/"));
String dayString =
dateString.substring(dateString.indexOf("/"),DateString.indexOf("/")+1)
Thank you. Edit. Thank you all for your responses, but my teacher said that i cannot use the split fucntion. He said I can solve this using just indexOf("/") and substring(). I'll need two calls to indexOf("/") and four calls to substring().
String[] element = dateString.split("/");
String strDay = element[0];
String strMonth = element[1];
String strYear = element[2];
Use String#split to get an array of the parts of your input string per your specified delimiter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With