Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ... | Java Program to find Nth term ; Function that will return nth term ; Driver Code ; Get n ; Get the value ; Get n ; Get the value
class GFG { static int getValue ( int n ) { int i = 0 , k = 1 ; while ( i < n ) { i = i + k ; k = k * 2 ; } return k / 2 ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( getValue ( n ) ) ; n = 1025 ; System . out . println ( getValue ( n ) ) ; } }