java Math.max

canyi·2023년 6월 22일
0

java m1

목록 보기
23/40

문제

price 배열의 값들을 coupon을 적용해서 합을 구함. 다만 price < coupon인 경우 그냥 더함.

풀이

import java.util.Arrays;

public class ex15 {
    public static void main(String[] args) {
        int[] price = {3000, 7000, 6000, 1000};
        int coupon = 2000;
        int dc = 0;

        for(int i = 0; i < price.length; i++ ){

            dc = dc + Math.max(0,price[i] - coupon);
        }

        System.out.println(dc);

    }
}

build

profile
백엔드 개발 정리

0개의 댓글