Contents

Baekjun no. 2525, oven clock (with.Java)

   Sep 20, 2024     2 min read

This is what we learned about Baekjun 2525 oven clock (with.Java).

I want to solve the coding test problem, find out how to solve it differently from the retrospective of the problem I solved, and get to know.

Let’s get to the problem first.

Problem

KOI Electronics is trying to develop an AI oven that makes healthy and delicious grilled smoked duck dishes simple.

The way to use an AI oven is to put the right amount of duck-smoked material into the AI oven.

Then, the artificial intelligence oven automatically calculates the time when the oven is finished in minutes.

Also, on the front of KOI Electronics’ AI oven is a digital clock that tells the user when grilled smoked duck cooking ends.

Write a program to calculate the time when the oven is finished, given the time to start the grilled smoked duck and the time required to bake the oven in minutes.

Input

The first line shows the current time.

The current time is given in order with time A (0≤A≤23) and minute B (0≤B≤59) as integers in between.

The second line is given in minutes the time C (0 ≤ C ≤ 1,000) required to cook.

Output

The time and minute of the time ending in the first line are output with a space between them.

(However, poetry is an integer from 0 to 23 and minutes is an integer from 0 to 59.

The digital clock will be 0:0 after one minute from 23:59.)

problem solving

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int hour = scan.nextInt();
        int minute = scan.nextInt();
        int working_time = scan.nextInt();

        hour += (minute + working_time) / 60;
        hour %= 24;
        minute = (minute + working_time) % 60;

        System.out.print(hour + " " + minute);
    }
}

Solution Description

Create a scanner object to prepare to receive input from the user.

Use the scan.nextInt() method to receive hour, minute, and working_time.

Divide the sum of the current minute and working_time by 60 to add to the hour.

If the calculated hour is more than 24, update it to the remaining value divided by 24 and keep it in 24-hour format.

Divide the sum of the current minute and working_time by 60 and update the remaining value to the new minute.

Outputs the calculated time and minutes.

Thank you!