首页 > 代码库 > 华为OJ:计算两个自然时间相加

华为OJ:计算两个自然时间相加

按要求一步步做就好

import java.util.Scanner;
public class dateAdd {
	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String s1=input.next();
		String s2=input.next();
		int s11=Integer.parseInt(s1.substring(0, 2));
		int s12=Integer.parseInt(s1.substring(3, 5));
		int s13=Integer.parseInt(s1.substring(6, 8));
		int s21=Integer.parseInt(s2.substring(0, 2));
		int s22=Integer.parseInt(s2.substring(3, 5));
		int s23=Integer.parseInt(s2.substring(6, 8));
		int s33=(s13+s23)%60;
		int s32=((s13+s23)/60+s12+s22)%60;
		int s31=((s12+s22)/60+s11+s21)%24;
		String str=String.format("%02d", s31)+':'+String.format("%02d", s32)+':'+String.format("%02d", s33);
		System.out.println(str);
	}
}