Nackey

if-else minutes and seconds

Jul 16th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Seconds {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int first = Integer.parseInt(scanner.nextLine());
  10.         int second = Integer.parseInt(scanner.nextLine());
  11.         int third = Integer.parseInt(scanner.nextLine());
  12.  
  13.         int sum = first + second + third;
  14.  
  15.         int minutes = 0;
  16.         int seconds = 0;
  17.  
  18.         if(sum<=59){
  19.             seconds = sum;
  20.         } else if (sum>59 && sum<=119){
  21.             minutes=1;
  22.             seconds = sum%60;
  23.         } else if(sum >119 && sum<=179){
  24.             minutes=2;
  25.             seconds=sum%60;
  26.         }
  27.         if (seconds<10){
  28.             System.out.printf("%s:0%s",minutes,seconds);
  29.         }else {
  30.             System.out.printf("%s:%s",minutes,seconds);
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment