package 实验十二;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
/**
*
* @Chapter:计算自己出生的天数
* @author ControlPower
* @version 1.7
* @data
* @remarks
* Ctrl + Shift + f 格式化代码
* java->Code Style ->Code Templates
* Alt + Shift + J 题目注释
*/
public class s5 {
public static void main(String[] args) {
GregorianCalendar gcal = new GregorianCalendar();
Calendar cal = Calendar.getInstance();
int sum = 0;
System.out.print("请输入出生年:");
int year = new Scanner(System.in).nextInt();
System.out.print("请输入出生月:");
int month = new Scanner(System.in).nextInt();
System.out.print("请输入出生日:");
int day = new Scanner(System.in).nextInt();
gcal.set(year, month - 1, day); //减一
String[] week = {"","星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
String str = String.format("您的出生日期是:%d年%d月%d日", gcal.get(Calendar.YEAR),gcal.get(Calendar.MONTH) + 1,gcal.get(Calendar.DAY_OF_MONTH));
str += " " + week[gcal.get(Calendar.DAY_OF_WEEK)];
System.out.println(str);
if(gcal.isLeapYear(gcal.get(Calendar.YEAR))) {
sum += 366 - gcal.get(Calendar.DAY_OF_YEAR);
}else {
sum += 365 - gcal.get(Calendar.DAY_OF_YEAR);
}
for (int i = gcal.get(Calendar.YEAR) + 1; i < cal.get(Calendar.YEAR); i++) {
if(gcal.isLeapYear(i)) {
sum += 366;
}else {
sum += 365;
}
}
sum += cal.get(Calendar.DAY_OF_YEAR);
System.out.println("您已经出生了:" + sum + "天");
}
}
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
/**
*
* @Chapter:计算自己出生的天数
* @author ControlPower
* @version 1.7
* @data
* @remarks
* Ctrl + Shift + f 格式化代码
* java->Code Style ->Code Templates
* Alt + Shift + J 题目注释
*/
public class s5 {
public static void main(String[] args) {
GregorianCalendar gcal = new GregorianCalendar();
Calendar cal = Calendar.getInstance();
int sum = 0;
System.out.print("请输入出生年:");
int year = new Scanner(System.in).nextInt();
System.out.print("请输入出生月:");
int month = new Scanner(System.in).nextInt();
System.out.print("请输入出生日:");
int day = new Scanner(System.in).nextInt();
gcal.set(year, month - 1, day); //减一
String[] week = {"","星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
String str = String.format("您的出生日期是:%d年%d月%d日", gcal.get(Calendar.YEAR),gcal.get(Calendar.MONTH) + 1,gcal.get(Calendar.DAY_OF_MONTH));
str += " " + week[gcal.get(Calendar.DAY_OF_WEEK)];
System.out.println(str);
if(gcal.isLeapYear(gcal.get(Calendar.YEAR))) {
sum += 366 - gcal.get(Calendar.DAY_OF_YEAR);
}else {
sum += 365 - gcal.get(Calendar.DAY_OF_YEAR);
}
for (int i = gcal.get(Calendar.YEAR) + 1; i < cal.get(Calendar.YEAR); i++) {
if(gcal.isLeapYear(i)) {
sum += 366;
}else {
sum += 365;
}
}
sum += cal.get(Calendar.DAY_OF_YEAR);
System.out.println("您已经出生了:" + sum + "天");
}
}