题解 | #小乐乐定闹钟#
小乐乐定闹钟
http://www.nowcoder.com/practice/0f7e422e12be4a7f9958ca2a82abc775
import java.util.Scanner;
// 主要是去掉天数的影响
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 时刻
String info = sc.nextLine();
String time = info.substring(0, info.indexOf(" "));
int minutes = Integer.valueOf( info.substring(info.indexOf(" ") + 1));
// 分钟数
int hour = Integer.valueOf(time.split(":")[0]);
int minute = Integer.valueOf(time.split(":")[1]);
// 不考虑天数
hour = (hour + minutes / 60 % 24) % 24;
minute = minute + minutes % 60;
// 可能加上原有的分钟数后又会超过60
if (minute >= 60) {
minute = minute % 60;
hour = hour + 1;
}
System.out.printf("%02d:%02d", hour, minute);
}
}