Computer Science, asked by haz269522, 4 days ago

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 anindyaadhikari13
12

\textsf{\large{\underline{Solution}:}}

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;

       }

   }

}

\textsf{\large{\underline{Explanation}:}}

  1. In this series, the first term is 0. So, the variable term is initialised with 0.
  2. Then, the difference between the second and first term is 3. So, the variable difference is initialized with 3.
  3. Then, a loop is created to display the first ten terms.
  4. 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.
  5. In this way, the problem is solved.

See the attachment for output.

Attachments:
Similar questions