修炼JAVA之路
需求:计算一个人活了多少天?
代码:
import java.util.Calendar;//导包,导入日历包
import java.util.Date;
import java.util.Scanner;
public class CalendarDemo {
public static void main(String[] args) {
Calendar now= Calendar.getInstance();//多态
long loacalTime1= now.getTimeInMillis();//日历直接获取当前时间的毫秒值
Scanner sc=new Scanner(System.in);
System.out.println(“请输入年”);
int year = sc.nextInt();
System.out.println(“请输入月”);
int month = sc.nextInt();
System.out.println(“请输入日”);
int day = sc.nextInt();
System.out.println(“请输入时”);
int hours = sc.nextInt();
System.out.println(“请输入分”);
int minutes = sc.nextInt();
System.out.println(“请输入秒”);
int seconds = sc.nextInt();
Calendar now1= Calendar.getInstance();//多态
now1.set(year,month,day,hours,minutes,seconds);
System.out.println("now1 = " + now1);
long birthDay = now1.getTimeInMillis();
double result=(loacalTime1-birthDay)/(10006060*24);
System.out.println("result = " + result);
![http://www.kaotop.com/file/tupian/20220508/8fa547495dd745f3afc4696ee0c032a4.png)
结果图20220507
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)