Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumSeconds_01 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //1. прочитаме времената, съхраним в променливи
- //2. общо време в секунди = в1 + в2 + в3
- //3. общо време в секунди -> минути и секунди
- //4. принтираме с водеща 0 (ако сек < 10 -> 0)
- int firstTime = Integer.parseInt(scanner.nextLine());
- int secondTime = Integer.parseInt(scanner.nextLine());
- int thirdTime = Integer.parseInt(scanner.nextLine());
- int totalTimeSeconds = firstTime + secondTime + thirdTime;
- int timeInMinutes = totalTimeSeconds / 60;
- int timeInSeconds = totalTimeSeconds % 60;
- //1. sec < 10
- if (timeInSeconds < 10) {
- //минути:0секунди
- System.out.printf("%d:0%d", timeInMinutes, timeInSeconds);
- } else {
- //минути:секунди
- //2. sec >= 10
- System.out.printf("%d:%d", timeInMinutes, timeInSeconds);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement