Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TimeAfter15Minutes_05 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //read hour, minutes
- int hour = Integer.parseInt(scanner.nextLine()); //23
- int minutes = Integer.parseInt(scanner.nextLine()); //59
- //calculate total in minutes = hour * 60 + minutes
- int totalInMinutes = hour * 60 + minutes; // 1439
- int totalInMinutesPlus15 = totalInMinutes + 15; //1439 + 15 = 1454
- //calculate endHour = totalAfter15 / 60
- //calculate endMinute = totalAfter % 60
- int endHour = totalInMinutesPlus15 / 60; //24
- int endMinutes = totalInMinutesPlus15 % 60; //14
- if(endHour == 24){
- endHour = 0;
- }
- //print hour:minute
- System.out.printf("%d:%02d",endHour, endMinutes);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement