![](https://i-blog.csdnimg.cn/blog_migrate/145d53218a881a359be51c1178739c12.png)
public class Main {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
System.out.println((int)Math.pow(20, 22)%7+6);
scan.close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/eab1e60f0e9f21c86ade20274db23c65.png)
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
int countyeah=0,yeah=1777,day=0,month=4;
String lingy="",lingr="";
for (int i = 0; i < 8113/366; i++) {
if (Run(++yeah)) {
countyeah++;
}
}
day =8113- (countyeah*366+(8113/365-countyeah)*365);
while (day>=30) {
if (month>=13) {
month=month-12;
}
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
month++;
day-=31;
case 4:
case 6:
case 9:
case 11:
month++;
day-=30;
break;
case 2:
if (Run(yeah)) {
month++;
day-=29;
}
else {
month++;
day-=28;
}
}
}
if (day>0) {
month++;
}
else {
day=29+day;
}
if (month<10) {
lingy="0"+month;
}
else {
lingy=month+"";
}
if (day<10) {
lingr="0"+day;
}
else {
lingr=day+"";
}
System.out.println(yeah+"-"+lingy+"-"+lingr);
}
public static boolean Run(int yeah) {
return ((yeah%4==0&&yeah%100!=0)||yeah%400==0)?true:false;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/79078d1b54190951520f88b62f42d888.png)
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
String date1 = scan.nextLine();
String date2 = scan.nextLine();
DateFormat format = new SimpleDateFormat("yyMMdd");
Date enDate = format.parse(date2);
Date start = format.parse(date1);
long e = enDate.getTime();
long s = start.getTime();
System.out.println((e-s)/(60*60*24*1000)+1);
}
}
java计算多少天后的日期
/**
* 计算多少天后的日期
* @param date 手动输入日期
* @param days 多少天后
* @return
* @throws ParseException
*/
public static String addDate(String date,int days) throws ParseException {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date parse = format.parse(date);
calendar.setTime(parse);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
// days 多少天后的日期
int newDay = day+days;
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month);
calendar.set(Calendar.DAY_OF_MONTH,newDay);
return format.format(calendar.getTime());
}
![](https://i-blog.csdnimg.cn/blog_migrate/80c4b25b4b7022d0ef97b910aa177bd4.png)
import java.util.Arrays;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
static int cnt = 0;
static int[]month = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
for (int i = 19000101; i <= 99991231; i++) {
if (check(i)&&calc(i)&&Check(i)) {
cnt++;
}
}
System.out.println(cnt);
scan.close();
}
private static boolean Check(int n) {
String s = n+"";
n = n/10000;
int m = Integer.parseInt(s.substring(4, 6));
if (!(n%4==0&&n%100!=0||n%400==0)) {//如果不是闰年 2月没有29天
if (Integer.parseInt(s.substring(6, 8))==29&&m==2) {
return false;
}
}
return true;
}
private static boolean check(int n) {
String s = n+"";
int day =Integer.parseInt(s.substring(6, 8));
int m = Integer.parseInt(s.substring(4, 6));
if (Integer.parseInt(s.substring(4, 6))>12||Integer.parseInt(s.substring(4, 6))==0) {
return false;
}
if (month[m]<day||day==0) {
return false;
}
return true;
}
private static boolean calc(int n) {
String s = n+"";
int a = sum(Integer.parseInt(s.substring(0, 4)));
int b = sum(Integer.parseInt(s.substring(4, 6)));
int c = sum(Integer.parseInt(s.substring(6, 8)));
if (a==b+c) {
return true;
}
return false;
}
private static int sum(int n) {
int Sum = 0;
while (n>0) {
Sum+=n%10;
n/=10;
}
return Sum;
}
}