Computer Science, asked by abhilashpalit2019tab, 6 months ago

Write a java program to print the sum of the following series. 0, 3, 8, 15 …. Upto n terms.

Answers

Answered by aairamashood16
0

The java program for the above question is as follows:

Explanation:

public class Series // Class definition

{

public static void main(String[] args)  // Main function declaration

{

int i=0,series=0,s=0; // variable declaration

while(i<10) // while loop to repeat the process 10 times.

{

    System.out.print(series+", "); // Print the series

    series=series+3+s; // Make the series

    i=i+1; // increment operator

    s=s+2; // increase for series

}

}

}

Output:

The user get "0, 3, 8, 15, 24, 35, 48, 63, 80, 99," as output because it is a series which is demand by the question.  

Code Explanation:

The above series is like this-- 0, 0+3, (0+3)+3+2, (0+3+3+2)+3+2 and so on.

Then the above program declares a while loop which executes 10 times.

Then it takes one variable which prints the value after adding the previous value and 3 and the s variable ( which starts from 0 and adds 2 value in previous value in every iteration of while loop).

                             

Answered by chaudharydorilal368
2

Answer:

hey mate here is your answer

Attachments:
Similar questions