题解 | #小乐乐定闹钟#
小乐乐定闹钟
https://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[] time = sc.nextLine().split("[: ]");
int k = Integer.parseInt(time[2]);
int hour = Integer.parseInt(time[0]) + (int) k / 60;
int minute = Integer.parseInt(time[1]) + k % 60;
hour = minute - 60 >= 0 ? hour + 1 : hour; //minute >= 60的时候,hour要加1;
hour = hour - 24 >= 0 ? hour % 24 : hour;//hour >= 24的时候,取对应的hour
minute = minute - 60 >= 0 ? minute- 60 : minute;//minute >= 60的时候,取对应的minute
System.out.print((hour < 10 ? "0"+hour: hour) + ":" + (minute< 10 ? "0"+minute : minute));
}
}
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String[] time = sc.nextLine().split("[: ]");
int k = Integer.parseInt(time[2]);
int hour = Integer.parseInt(time[0]) + (int) k / 60;
int minute = Integer.parseInt(time[1]) + k % 60;
hour = minute - 60 >= 0 ? hour + 1 : hour; //minute >= 60的时候,hour要加1;
hour = hour - 24 >= 0 ? hour % 24 : hour;//hour >= 24的时候,取对应的hour
minute = minute - 60 >= 0 ? minute- 60 : minute;//minute >= 60的时候,取对应的minute
System.out.print((hour < 10 ? "0"+hour: hour) + ":" + (minute< 10 ? "0"+minute : minute));
}
}