Sum of series with alternate signed squares of AP | Java program to find sum of series with alternate signed square AP sums . ; function to calculate series sum ; Driver code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int seiresSum ( int n , int [ ] a ) { int res = 0 , i ; for ( i = 0 ; i < 2 * n ; i ++ ) { if ( i % 2 == 0 ) res += a [ i ] * a [ i ] ; else res -= a [ i ] * a [ i ] ; } return res ; } public static void main ( String args [ ] ) { int n = 2 ; int a [ ] = { 1 , 2 , 3 , 4 } ; System . out . println ( seiresSum ( n , a ) ) ; } }