Find Nth term of the series where each term differs by 6 and 2 alternately | Java program for the above approach ; Function to find Nth term ; Iterate from 1 till Nth term ; Check if i is even and then add 6 ; Else add 2 ; Print ans ; Driver Code
class GFG { static void findNthTerm ( int N ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { ans = ans + 6 ; } else { ans = ans + 2 ; } } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 3 ; findNthTerm ( N ) ; } }