-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXDistanceNum.java
More file actions
36 lines (35 loc) · 1.02 KB
/
Copy pathXDistanceNum.java
File metadata and controls
36 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package level1;
/*
* 함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다.
* 다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요.
제한 조건
x는 -10000000 이상, 10000000 이하인 정수입니다.
n은 1000 이하인 자연수입니다.
입출력 예
x n answer
2 5 [2,4,6,8,10]
4 3 [4,8,12]
-4 2 [-4, -8]
*/
public class XDistanceNum {
public static void main(String[] args) {
SolutionXDistanceNum su = new SolutionXDistanceNum();
int x = 2;
int n = 5; // 2,4,6,8,10
// int x = 4;
// int n = 3; // 4, 8, 12
// int x = -4;
// int n = 2; // -4, -8
for(long data : su.solution(x, n))
System.out.print(data + " ");
}
}
class SolutionXDistanceNum {
public long[] solution(int x, int n) {
long[] answer = new long[n];
for(int i=0; i<answer.length; i++) {
answer[i] = (Long.valueOf(x) *(i + 1));
}
return answer;
}
}