Sum of first n odd numbers in O ( 1 ) Complexity | Java program to find sum of first n odd numbers ; Returns the sum of first n odd numbers ; driver function
import java . util . * ; class Odd { public static int oddSum ( int n ) { return ( n * n ) ; } public static void main ( String [ ] args ) { int n = 20 ; System . out . println ( " ▁ Sum ▁ of ▁ first ▁ " + n + " ▁ Odd ▁ Numbers ▁ is : ▁ " + oddSum ( n ) ) ; } }