-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandies.java
More file actions
30 lines (28 loc) · 722 Bytes
/
Candies.java
File metadata and controls
30 lines (28 loc) · 722 Bytes
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
class Candies{
static void candies(int n, int k) {
int[] arr = new int[k];
int j = 0;
while (n > 0) {
for (int i = 0; i < k; i++) {
j++;
if (n <= 0) {
break;
} else {
if (j < n) {
arr[i] = arr[i] + j;
} else {
arr[i] = arr[i] + n;
}
n = n - j;
}
}
}
for (int i : arr) {
System.out.print(i + " ");
}
}
public static void main(String[] args) {
int n = 10, k = 3;
candies(n,k);
}
}