I am trying to split a string into different array indexes. This string is coming from user input (through java.util.Scanner
) and is being loaded into a String
variable. How can I split the input from the string into different array indexes?
Also, how can I do the math functions that are implied by DOB
being an int
?
Here is my code:
import java.util.Scanner;
public class main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter date of birth (MM/DD/YYYY):");
String DOB;
DOB = input.next();
int age = 0;
age = 2013 - DOB - 1;
int age2 = 0;
age2 = age + 1;
System.out.println("You are " + age + " or " + age2 + " years old");
}
}