I want to build a copy of code that involves method and array. My intention is to display a date that will be entered by the user.
But I get an error:
array required, but string found
This is part of my code:
public class Reservation{
public static Scanner input=new Scanner(System.in);
public static String[] date=new String[5];
public static int arraylength=5;
public static int index;
public static void main (String[] args){
start();
}
//this is the method where the date will be entered
public static void register(){
for(index=0;index<date.length;index++){
System.out.print("Enter the date of reservation(DD/MM/YY): ");
date[index]=input.nextLine();
}
}
// this is the method where date will be display
public static void display(String date, int index,int arraylength){
for(index=0;index<arraylength;index++){
System.out.println("The date ["+index+"]: "+date[index]);
}
}
}
displaymethod, you provideStringobject and try iterating through it as it was an array?