본문 바로가기

프로그래머스

[프로그래머스] x만큼 간격이 있는 n개의 숫자_ JAVA

● 문제


● 풀이

 

import java.util.*;
import java.io.*;

class Solution {
    public long[] solution(int x, int n) {
        long[] answer = new long[n];
        
        answer[0] = x;
        
        for(int i =1; i<n; i++){
            answer[i] = answer[i-1] + x;
        }
        
        return answer;
    }
}