0

我有作业,我必须编写一个小程序,要求输入一个数字并返回分配给该数字的月份。

到目前为止,我已经编写了两个不同的类,一个是提示用户输入 int,另一个是月份数组。现在我的问题是当用户输入数字时将几个月传递给主类。

到目前为止,对于主要课程,我有这个,我不知道如何继续......我得到:

java:17: error: array required, but Date found System.out.println(monthName[index]); 

我试图尽可能详细。

    import java.util.Scanner;

public class Driver {

    public static void main(String[] args)
    {
        Utility input = new Utility();
        final int MONTH_NAMES = 12;
        int[] month = new int[MONTH_NAMES];
        Date monthName = new Date();
        {
        System.out.println(input.queryForInt("Enter the number for a month ")) ;
        }


    for (int index = 0; index < 12; index++)
        System.out.println(monthName[index]);
}
}
4

3 回答 3

0

您的 System.out 行没有引用您命名为月份的数组。

于 2013-09-30T21:56:53.380 回答
0

我不认为你打算在Date monthName这里使用

System.out.println(monthName[index]);

从您的循环计算的索引数量来看,您for似乎想使用int[] month.

System.out.println(month[index]);
于 2013-09-30T21:58:25.987 回答
0

mouthName 是一个 Date 对象,而不是一个数组。另外,为什么要使用 for 循环来打印一整年的嘴巴?

我认为System.out.printLn(mouthName.getMouth())如果 input.queryForIntmethod 可以成功地将 int 口传递给mouthName 对象,它可以将最后一个 for 循环更改为。

于 2013-09-30T22:06:08.787 回答