Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class SecondsSumming {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int repeats = 3;
- int sum = 0;
- ArrayList<Integer> seconds = new ArrayList<>();
- for (int i = 0; i < repeats; i++){
- seconds.add(scan.nextInt());
- }
- sum = summingSeconds(seconds);
- convertingToTime(sum);
- }
- public static int summingSeconds(ArrayList<Integer> secondsToSum){
- int sum = 0;
- for (int i = 0; i < secondsToSum.size(); i++){
- sum+= secondsToSum.get(i);
- }
- return sum;
- }
- public static void convertingToTime(int timeInSeconds){
- int seconds = 0;
- int minutes = 0;
- int hours = 0;
- hours = timeInSeconds / 3600;
- minutes = (timeInSeconds - hours*3600) / 60;
- seconds = timeInSeconds % 60;
- System.out.printf(String.format("%02d:%02d", minutes, seconds));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment