2 u010394095 u010394095 于 2013.10.24 22:35 提问

代码执行后与想要的答案不一致

package day01;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test01 {
public static void main(String[] args) throws ParseException {
System.out.println("请输入生产日期:");
Scanner in=new Scanner(System.in);
String date=in.nextLine();
System.out.println("请输入保质日期:");
int day=in.nextInt();

System.out.println("促销时间是:"+getDate(date,day));
in.close();

}
public static String getDate(String date,int day) throws ParseException{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date dat=sdf.parse(date);
Calendar calendar=Calendar.getInstance();
calendar.setTime(dat);
calendar.add(Calendar.DAY_OF_YEAR, day);
calendar.add(Calendar.WEEK_OF_YEAR, -2);
calendar.add(Calendar.DAY_OF_WEEK, 4);

String dates=sdf.format(calendar.getTime());
return dates;

}
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!