将以下代码改错:import java.time.*; import java.util.Scanner; import java.time.temporal.ChronoUnit; public class CompareDate { public static void main(String args[ ]) { Scanner scanner = new Scanner(System.in); System.out.println("输入开始的年,月,日 "); System.out.println("年月日之间用-,/或.分隔\n例如:2018-2-12"); String regex = "[-./]"; String [] input = scanner.nextLine().split(regex); int year = Integer.parseInt(input[0]); int month = Integer.parseInt(input[1]); int day = Integer.parseInt(input[2]); LocalDate dateStart = null; 【代码1】// LocalDate调用of方法,返回年月日分别是year,,month,day的dateSart对象 System.out.print("输入结束的年,月,日:"); input = scanner.nextLine().split(regex); year = Integer.parseInt(input[0]); month = Integer.parseInt(input[1]); day = Integer.parseInt(input[2]); LocalDate dateEnd = null; 【代码2】// LocalDate调用of方法返回年月日分别是year,,month,day的dateEnd对象 long days = 【代码3】//得到dateStart和dateEnd相隔的天数 boolean boo = 【代码4】//判断dateEnd是否在dateStart之后 if(boo) System.out.println(dateEnd+"在"+dateStart+"之后"); System.out.println(dateStart+"和"+dateEnd+"相隔:"); System.out.println(Math.abs(days)+"天(不足一天的零头按0计算)"); } }
时间: 2023-06-10 16:07:16 浏览: 125
import java.time.*;
import java.util.Scanner;
import java.time.temporal.ChronoUnit;
public class CompareDate {
public static void main(String args[ ]) {
Scanner scanner = new Scanner(System.in);
System.out.println("输入开始的年,月,日 ");
System.out.println("年月日之间用-,/或.分隔\n例如:2018-2-12");
String regex = "[-./]";
String [] input = scanner.nextLine().split(regex);
int year = Integer.parseInt(input[0]);
int month = Integer.parseInt(input[1]);
int day = Integer.parseInt(input[2]);
LocalDate dateStart = null;
// 代码1
dateStart = LocalDate.of(year, month, day);
System.out.print("输入结束的年,月,日:");
input = scanner.nextLine().split(regex);
year = Integer.parseInt(input[0]);
month = Integer.parseInt(input[1]);
day = Integer.parseInt(input[2]);
LocalDate dateEnd = null;
// 代码2
dateEnd = LocalDate.of(year, month, day);
// 代码3
long days = ChronoUnit.DAYS.between(dateStart, dateEnd);
// 代码4
boolean boo = dateEnd.isAfter(dateStart);
if(boo)
System.out.println(dateEnd + "在" + dateStart + "之后");
System.out.println(dateStart + "和" + dateEnd + "相隔:");
System.out.println(Math.abs(days) + "天(不足一天的零头按0计算)");
}
}
阅读全文