I have been looking for an answer but I haven't had luck finding one that can quite help me (someone may know where to point me).
I want to split a string up into a string variable and two integer variables. I am wondering if there is anyway to user the string split method I discovered and use it for int variables through some other way?
Code:
import java.util.Scanner;
public class StringInputStream {
public static void main (String [] args) {
Scanner inSS = null;
String userInput = "Jan 12 1992";
inSS = new Scanner(userInput);
String userMonth = "";
int userDate = 0;
int userYear = 0;
// Can modify anything below here
String[] temp = userInput.split(" ", 2); // "1" means stop splitting after one space
userMonth = temp[0];
userDate = temp[1];
userYear = temp[2];
// Can modify anything above here
System.out.println("Month: " + userMonth);
System.out.println("Date: " + userDate);
System.out.println("Year: " + userYear);
return;
}
}
Example output:
Month: Jan
Date: 12
Year: 1992
