forked from sPredictorX1708/Ultimate-Java-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaLoops2.java
More file actions
39 lines (34 loc) · 1003 Bytes
/
JavaLoops2.java
File metadata and controls
39 lines (34 loc) · 1003 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
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
class JavaLoops2 {
public static void main(String[] argh) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
printAP(a, b, n);
}
in.close();
}
private static void printAP(int a, int b, int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
int sumOfPowers = calculatePower(i, b);
arr[i] = a + sumOfPowers;
if (i < n - 1) {
System.out.print(arr[i] + " ");
} else {
System.out.println(arr[i]);
}
}
}
private static int calculatePower(int i, int b) {
int sum = 0;
for (int j = 0; j <= i; j++) {
int oneValue = (int) (Math.pow(2, j)) * b;
sum = sum + oneValue;
}
return sum;
}
}