Skip to content

Commit b46eff1

Browse files
committed
Quadratic Sequence
1 parent 5e0d22e commit b46eff1

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.java.series;
2+
3+
/*
4+
* Quadratic Sequence
5+
*
6+
* A quadratic sequence is a sequence of numbers
7+
* in which the second difference between
8+
* any two consecutive terms is constant.
9+
*
10+
* Say the series
11+
* 1 2 4 7 11 16 22 29 .....
12+
*
13+
* It is simple to calculate the next term
14+
* ith term = (i-1)th term + (i-1)
15+
* where i starts from 1
16+
*
17+
* term 1 : 1
18+
* term 2 = 1 + 1 = 2
19+
* term 3 = 2 + 2 = 4
20+
* term 4 = 4 + 3 = 7
21+
* term 5 = 7 + 4 = 11
22+
* term 6 = 11 + 5 = 16
23+
* term 7 = 16 + 6 = 22
24+
*
25+
* The Series is
26+
* 1, 2, 4, 7, 11, 16, 22
27+
*/
28+
public class QuadraticSequence {
29+
public static void main(String[] args) {
30+
int n = 15;
31+
System.out.println("The Series is : ");
32+
int prevTerm = 1;
33+
System.out.print(prevTerm+", ");
34+
for(int i=2; i<=n; i++){
35+
prevTerm = prevTerm + i-1;
36+
System.out.print(prevTerm+", ");
37+
}
38+
}
39+
}
40+
/*
41+
OUTPUT
42+
n = 10
43+
The Series is :
44+
1, 2, 4, 7, 11, 16, 22, 29, 37, 46,
45+
46+
OUTPUT
47+
n = 15
48+
The Series is :
49+
1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106,
50+
51+
*/

0 commit comments

Comments
 (0)