时间换算
本题要求编写程序,以hh:mm:ss
的格式输出某给定时间再过n秒后的时间值(超过23:59:59就从0点开始计时)。
输入格式:
输入在第一行中以hh:mm:ss
的格式给出起始时间,第二行给出整秒数n(<60)。
输出格式:
输出在一行中给出hh:mm:ss
格式的结果时间。
输入样例:
11:59:40
30
输出样例:
12:00:10
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int hours , minutes , seconds , temp,addition , all_seconds;
String all , temp_string;
all = input.next();
temp_string = all.substring(all.lastIndexOf(":")+1);
seconds = Integer.parseInt(temp_string);
temp_string = all.substring(0, all.indexOf(":"));
hours = Integer.parseInt(temp_string);
temp_string = all.substring(all.indexOf(":")+1, all.lastIndexOf(":"));
minutes = Integer.parseInt(temp_string);
addition = input.nextInt();
all_seconds = minutes * 60 + hours*3600 + seconds;
all_seconds = all_seconds +addition;
hours = all_seconds/3600;
temp = all_seconds;
temp = temp%3600;
if(hours>=24)
hours = hours%24;
minutes = temp / 60;
seconds = temp % 60;
System.out.printf("%02d:%02d:%02d", hours,minutes,seconds);
input.close();
}
}