Find nth term of a given recurrence relation | Java program to find nth term of a given recurrence relation ; function to return required value ; Get the answer ; Return the answer ; Driver code ; Get the value of n ; function call to print result
import java . util . * ; class solution { static int sum ( int n ) { int ans = ( n * ( n - 1 ) ) / 2 ; return ans ; } public static void main ( String arr [ ] ) { int n = 5 ; System . out . println ( sum ( n ) ) ; } }