有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java类型日历中的方法集(int,int)不适用于参数(int,String)

Java代码从给定的星期几、月周、月和年创建日期作为输入。示例-如果IPUT如下所示:

day-Monday, month-july, week-1, year-2018,

那么产量应该是2018年7月2日

下面是使用的代码:

        System.out.println("Enter a year,month,week,day:");
        int year = Integer.parseInt(obj.nextLine());
        int month = Integer.parseInt(obj.nextLine());
        int week = Integer.parseInt(obj.nextLine());
        String day = obj.nextLine();

        String date;

        SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd");

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year); // set the year
        cal.set(Calendar.MONTH, month-1); // set the month
        cal.set(Calendar.WEEK_OF_MONTH, week);

        //***error in the below line********
        cal.set(Calendar.DAY_OF_WEEK,day);

        date=dateFormat.format(cal.getTime());
        System.out.println("Result:" +date);

标记的行无法编译。为什么不呢?我该怎么修


共 (0) 个答案