Contents

Iced Americano (with.Java)

   Feb 2, 2024     1 min read

This article looks into the “Iced Americano” issue.

As I solve coding test problems, I look back on the problems I solved and look into different solution methods to learn more.

Let’s look at the problem first.

problem

Even on cold days, I only drink iced Americano.

Iced Americano costs 5,500 won per glass.

Complete the solution function to return an array containing the maximum number of cups of Americano the mugger can drink and the remaining money in order when the money the muggle has is given as a parameter.

Restrictions

0 < money ≤ 1,000,000

Input/Output Example

moneyresult
5,500[1, 0]
15,000[2, 4000]

My solution to the problem

class Solution {
     public int[] solution(int money) {
         int[] answer = new int[2];
         answer[0] = money / 5500;
         answer[1] = money % 5500;
         return answer;
     }
}

Solution explanation

int[] answer = new int[2];: Creates an array answer to store two integers.

answer[0] = money / 5500;: Stores the quotient of the input amount money divided by 5500 in the first element of the array. This indicates how many times it is divisible by 5500.

answer[1] = money % 5500;: Divide the input amount money by 5500 and store the remainder in the second element of the array. This represents the amount remaining when divided by 5500.

return answer;: returns an array answer where the calculated quotient and remainder are stored.

This code divides the entered amount by 5500 and returns the quotient and remainder in an array.