【发布时间】:2016-01-01 13:48:56
【问题描述】:
我想构建一个涉及方法和数组的代码副本。我的意图是显示用户将输入的日期。但是出现了array required, but string found 错误。这是我的代码的一部分:
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]);
}
}
}
【问题讨论】:
-
在您的
display方法中,您提供String对象并尝试遍历它,因为它是一个数组?