PTA_时间换算_JAVA

时间换算


本题要求编写程序,以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();			
	}

}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值