Average of first n odd naturals numbers | Java program to find average of sum of first n odd natural numbers . ; Returns the Avg of first n odd numbers ; sum of first n odd number ; Average of first n odd numbers ; Driver Code
import java . io . * ; class GFG { static int avg_of_odd_num ( int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( 2 * i + 1 ) ; return sum / n ; } public static void main ( String [ ] args ) { int n = 20 ; avg_of_odd_num ( n ) ; System . out . println ( avg_of_odd_num ( n ) ) ; } }