Find final value if we double after every successful search in array | Java program to find value if we double the value after every successful search ; Function to Find the value of k ; Search for k . After every successful search , double k . ; Driver Code
class GFG { static int findValue ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == k ) k *= 2 ; return k ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 10 , 8 , 1 } , k = 2 ; int n = arr . length ; System . out . print ( findValue ( arr , n , k ) ) ; } }