InterviewSolution
Saved Bookmarks
| 1. |
Write a program in Java to print the sum of the series 1 – 2 + 32 – 4 + 5 - 62 + 7 – 8 + 92 – 10 …n terms |
|
Answer» tion:// JAVA program to find summation of series IMPORT java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; class GFG { // function to calulate sum of series static int summingSeries(long n) { // use of LOOP to calculate // sum of each term int S = 0; for (i = 1; i <= n; i++) S += i * i - (i - 1) * (i - 1); return S; } // Driver code public static VOID MAIN(String[] args) { int n = 100; System.out.println("The sum of n term is: " + summingSeries(n)); } } |
|