参考代码:
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语言代码)浏览:2354 |
C语言训练-排序问题<2> (C++代码)(sort函数)浏览:1604 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:733 |
C语言训练-排序问题<2> (C++代码)浏览:904 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:684 |
回文数(一) (C语言代码)浏览:779 |
WU-格式化数据输出 (C语言代码)浏览:1767 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:700 |
1128题解(返回值为数组的情况)浏览:484 |
【偶数求和】 (C语言代码)浏览:444 |