Computer Science, asked by JoyeetaDas, 10 months ago

write a program in java to print the series: 2,6,12,20,30...n​

Answers

Answered by ridhimakh1219
2

Write a program in java to print the series: 2,6,12,20,30...n​

Explanation:

Terms in series is calculated as below:

1 X 1 + 1 = 2

2 X 2 + 2 = 6

3 X 3 + 3 = 12

4 X 4 + 4 = 20

5 X 5 + 5 = 30................, so on

Java Program

import java.util.*;

public class Main

{

public static void main(String args[])  

{  

   int n;

   System.out.println("Enter nth term upto which series is printed  ");

   Scanner in = new Scanner(System.in);

   n = in.nextInt();

   for(int i=1;i<=n;i++)

   {

   int d =i*i+i;

   System.out.print(d+",");

   }

}

}  

OUTPUT

Enter nth term upto which series is printed                                                                        

10                                                                                                                  

2,6,12,20,30,42,56,72,90,110,

Similar questions