-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathSeries1.java
More file actions
40 lines (37 loc) · 742 Bytes
/
Series1.java
File metadata and controls
40 lines (37 loc) · 742 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
40
package com.java.series;
/*
* Print the following Series
* 2 9 28 65 126 217 344
* -------------------------
* for i-th element
* (i^3)+1
*
* i = 1 => 1^3+1 = 1 + 1 = 2
* i = 2 => 2^3+1 = 8 + 1 = 9
* i = 3 => 3^3+1 = 27 + 1 = 28
* i = 4 => 4^3+1 = 64 + 1 = 65
* i = 5 => 5^3+1 = 125 + 1 = 126
* i = 6 => 6^3+1 = 216 + 1 = 217
* i = 7 => 7^3+1 = 343 + 1 = 344
*
*/
public class Series1 {
public static void main(String[] args) {
int n = 10;
System.out.println("The Series is : ");
for(int i=1;i<=n;i++){
int value = (i*i*i) + 1;
System.out.print(value+", ");
}
}
}
/*
OUTPUT
n = 10
The Series is :
2, 9, 28, 65, 126, 217, 344, 513, 730, 1001
OUTPUT
n = 5
The Series is :
2, 9, 28, 65, 126
*/