Good day to you all, I just want to ask what to do with this.. I want to create program where i can display all the dates inputted without the separator "/" so I used the split method to do it. to be more clear this what I want to do:
Input
Enter Date:10/11/1994
Enter Date:11/10/2008
Enter Date:12/12/2010
Enter Date:08/12/1999
Enter Date:09/10/2005
Output:
10 11 1994
11 10 2008
12 12 2010
08 12 1999
09 10 2005
The problem is it I have an error
in System.out.println(comp[ctr1]);
it says that I have to initialize the comp
variable, actually I don't what Initialization I will use. I tried using String[] comp=new String[date]
and String[] comp=new String[5]
but it is still an error.. Thanks in advance..
String[] date=new String[5];
String[] comp;
int mm, dd, yyyy;
for(int ctr=0;ctr<date.length;ctr++){
System.out.print("Enter Date: ");
date[ctr]=input.nextLine();
comp=date[ctr].split("/");
mm=Integer.parseInt(comp[0]);
dd=Integer.parseInt(comp[1]);
yyyy=Integer.parseInt(comp[2]);
}
for(int ctr1=0;ctr1<date.length;ctr1++){
System.out.println(comp[ctr1]);
}