Java

프로그래머스: 없는 숫자 더하기

Daeryuk Kim 2024. 1. 20. 16:32
class Solution {
   public int solution(int[] numbers) {
        int answer = 45;
       
       // 1~10 = 55 
       // 55 - 10 = 45 
       
       for (int x=0; x<numbers.length; x++) {
           answer -= numbers[x];
       }
        return answer;
    }
    
    public static void main(String[] args) {
        
        int[] numbers = {1,2,3,4,6,7,8,0};
        
        Solution sol = new Solution();
        int result = sol.solution(numbers);
     
        System.out.println(result); 
        
    }
}