Write a program to display the first ten terms of the following series. 0, 3, 8, 15, 24,………., 99 (Variable description is not required.)
Answers
Answered by
12
public class Main{
public static void main(String s[]){
int n=10,i,term=0,difference=3;
System.out.println("Here is your series!!\n");
for(i=1;i<=n;i++){
System.out.print(term+" ");
term+=difference;
difference+=2;
}
}
}
- In this series, the first term is 0. So, the variable term is initialised with 0.
- Then, the difference between the second and first term is 3. So, the variable difference is initialized with 3.
- Then, a loop is created to display the first ten terms.
- Each term is displayed and then the difference is added to the term to obtain the next term. Also, the difference is incremented by 2 to get the difference between next two terms.
- In this way, the problem is solved.
See the attachment for output.
Attachments:
Similar questions