参考代码:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class Main { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws ParseException//日期时间格式的抛异常 { int n = scanner.nextInt(); scanner.nextLine(); while(n-- > 0) { int to = getTime(); int back = getTime(); int res = (to + back) / 2;//飞去的时间时是:飞行时间-时差,回来的时间是:飞行时间+时差 System.out.printf("%02d:%02d:%02d\n", res / 3600, res / 60 % 60, res % 60); //printf前置0,防空位 } } static int getTime() throws ParseException { String[] in = scanner.nextLine().split(" "); SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");//format类的自定义时间格式匹配 Date start = format.parse(in[0]); Date end = format.parse(in[1]); int t = 0; if(in.length > 2) t = Integer.parseInt(in[2].substring(2, 3)); return (int) ((end.getTime() - start.getTime()) / 1000 + t * 24 * 3600);//Date类返回的是纳秒 } }
0.0分
0 人评分
C二级辅导-阶乘数列 (C语言代码)浏览:731 |
愚蠢的摄影师 (C++代码)浏览:964 |
Hello, world! (C语言代码)浏览:760 |
C二级辅导-同因查找 (C语言代码)浏览:609 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:636 |
回文数(一) (C语言代码)浏览:1165 |
1073题解浏览:649 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:605 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:401 |
C语言程序设计教程(第三版)课后习题5.5 (Java代码)浏览:557 |