Program to toggle K | Java program to toggle K - th bit of a number N ; Function to toggle the kth bit of n ; Driver code
class GFG { static int toggleBit ( int n , int k ) { return ( n ^ ( 1 << ( k - 1 ) ) ) ; } public static void main ( String [ ] args ) { int n = 5 , k = 2 ; System . out . printf ( "%dNEW_LINE", toggleBit(n, k)); } }