Find sum of the series 1 | Java program to find sum of first n terms of the given series ; when n is odd ; when n is not odd ; Driver code ; no . of terms to find the sum
import java . util . * ; class GFG { static int calculateSum ( int n ) { if ( n % 2 == 1 ) return ( n + 1 ) / 2 ; return - n / 2 ; } public static void main ( String ar [ ] ) { int n = 8 ; System . out . println ( calculateSum ( n ) ) ; } }