← all problems

Seconds to minutes and seconds 🌶️🌶️

The variable totalSeconds holds a length of time in seconds. The three locked lines at the bottom print it in the form minutes:seconds, using two variables named minutes and seconds. There aren't any variables named minutes and seconds, so you have to make them. Write the code in the box that declares each one as an int and gives it the right value: how many whole minutes are in totalSeconds, and how many seconds are left over. Every test uses a total whose leftover seconds have two digits, so you don't need to worry about padding with a leading zero.

You'll fix this to work with all numbers of seconds in unit two!

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        int totalSeconds = 135;
        // ---- write your code below ----
        System.out.print(minutes);
        System.out.print(":");
        System.out.println(seconds);
    }
}