Count of pairs with sum N from first N natural numbers | Java program to count the number of pairs among the first N natural numbers with sum N ; Function to calculate the value of count ; If n is even ; Count of pairs ; Otherwise ; Driver code
import java . io . * ; class GFG { public static int numberOfPairs ( int n ) { if ( n % 2 == 0 ) return n / 2 - 1 ; else return n / 2 ; } public static void main ( String [ ] args ) { int n = 8 ; System . out . println ( numberOfPairs ( n ) ) ; } }