参考代码:
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语言代码)浏览:686 |
WU-C语言程序设计教程(第三版)课后习题11.11 (C++代码)(想学链表的可以看看)浏览:1436 |
【求[X,Y]内被除3余1并且被除5余3的整数的和】 (C语言代码)浏览:698 |
Cylinder (C语言描述+详细分析)浏览:3333 |
简单的a+b (C语言代码)浏览:611 |
判定字符位置 (C++代码)浏览:724 |
1415题求解浏览:675 |
P1044 (C++代码)浏览:542 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:636 |
简单的a+b (C语言代码)浏览:359 |