Ways to choose balls such that at least one ball is chosen | Java implementation of the approach ; Function to return the count of ways to choose the balls ; Calculate ( 2 ^ n ) % MOD ; Subtract the only where no ball was chosen ; Driver code
class GFG { static int MOD = 1000000007 ; static int countWays ( int n ) { int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { ans *= 2 ; ans %= MOD ; } return ( ( ans - 1 + MOD ) % MOD ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countWays ( n ) ) ; } }