public class oneday {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入放假月份");
int month1=input.nextInt();
System.out.println("请输入放假日期");
int day1=input.nextInt();
System.out.println("请输入开学月份");
int month2=input.nextInt();
System.out.println("请输入开学日期");
int day2=input.nextInt();
//计算开学日期,如果开学日期是8月,则日期要把7月的31天加进去
if(month1==8) {
day1=day1+31;
}
if(month2==8) {
day2=day2+31;
}
//最重要的:要获取到所有停电的日期
int sum=1;
ArrayList<Integer> list=new ArrayList<>();
for (int i = 1; i <=62; i+=sum) {
System.out.println(i);
list.add(i);//将停电的日期存入集合
sum++;
}
System.out.println(list.toString());
int sum0=0;//累计停电的天数
for (int i = 0; i < list.size(); i++) {
if(list.get(i)>=day1) {
sum0++;
}
if(list.get(i)>day2) {
break;
}
}
System.out.println("总共要停电:"+sum0+"天!");
}
}
标签:停电,开学,int,System,日期,input From: https://www.cnblogs.com/jiahaozhang/p/16818834.html