codeparrot/xlcost-text-to-code huggingface dataset:
Represent the given number as the sum of two composite numbers | Java implementation of the approach ; Function to find two composite numbers which when added give sum as n ; Only 8 and 10 can be represented as the sum of two composite integers ; If n is even ; If n is odd ; Driver code
class GFG { static void findNums ( int n ) { if ( n <= 11 ) { if ( n == 8 ) System . out . print ( "4 ▁ 4" ) ; if ( n == 10 ) System . out . print ( "4 ▁ 6" ) ; else System . out . print ( " - 1" ) ; return ; } if ( n % 2 == 0 ) System . out . print ( "4 ▁ " + ( n - 4 ) ) ; else System . out . print ( "9 ▁ " + ( n - 9 ) ) ; } public static void main ( String args [ ] ) { int n = 13 ; findNums ( n ) ; } }
Count of N | Java implementation of the approach ; Function to return the count of possible numbers ; Driver code
class GFG { static int count ( int n ) { return ( int ) Math . pow ( 2 , n - 1 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( count ( n ) ) ; } }
Find the next fibonacci number | Java implementation of the approach ; Function to return the next fibonacci number ; Driver code
class GFG { static long nextFibonacci ( int n ) { double a = n * ( 1 + Math . sqrt ( 5 ) ) / 2.0 ; return Math . round ( a ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( nextFibonacci ( n ) ) ; } }
Sum of all the numbers present at given level in Pascal 's triangle | Java implementation of the approach ; Function to find sum of numbers at Lth level in Pascals Triangle ; Driver Code
class GFG { static int sum ( int h ) { return ( int ) Math . pow ( 2 , h - 1 ) ; } public static void main ( String [ ] args ) { int L = 3 ; System . out . println ( sum ( L ) ) ; } }
Product of values of all possible non | Java implementation of the approach ; Function to find product of all elements in all subsets ; Driver Code
class GFG { static int product ( int a [ ] , int n ) { int ans = 1 ; int val = ( int ) Math . pow ( 2 , n - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { ans *= ( int ) Math . pow ( a [ i ] , val ) ; } return ans ; } public static void main ( String [ ] args ) { int n = 2 ; int a [ ] = { 3 , 7 } ; System . out . println ( product ( a , n ) ) ; } }
Program to find Nth odd Fibonacci Number | Java program for Nth odd fibonacci number ; Function to find nth odd fibonacci number ; Driver Code
class GFG { static int oddFib ( int n ) { n = ( 3 * n + 1 ) / 2 ; int a = - 1 , b = 1 , c = 0 , i ; for ( i = 1 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( oddFib ( n ) ) ; } }
Find a pair ( n , r ) in an integer array such that value of nPr is maximum | Java implementation of the approach ; Function to print the pair ( n , r ) such that nPr is maximum possible ; There should be atleast 2 elements ; Findex the largest 2 elements ; Driver code
class GFG { static void findPair ( int arr [ ] , int n ) { if ( n < 2 ) { System . out . print ( " - 1" ) ; return ; } int i , first , second ; first = second = - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) { second = arr [ i ] ; } } System . out . println ( " n ▁ = ▁ " + first + " ▁ and ▁ r ▁ = ▁ " + second ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 } ; int n = arr . length ; findPair ( arr , n ) ; } }
Sum of values of all possible non | Java implementation of the approach ; Function to return the required sum ; Find the sum of the array elements ; Every element appears 2 ^ ( n - 1 ) times ; Driver code
class GFG { static int sum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } sum = sum * ( int ) Math . pow ( 2 , n - 1 ) ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 5 , 6 } ; int n = arr . length ; System . out . println ( sum ( arr , n ) ) ; } }
Printing the Triangle Pattern using last term N | Java code for printing the Triangle Pattern using last term N ; Function to demonstrate printing pattern ; number of spaces ; character to be printed ; outer loop to handle number of rows n in this case ; inner loop to handle number spaces values changing acc . to requirement ; decrementing k after each loop ; inner loop to handle number of columns values changing acc . to outer loop ; printing stars ; ending line after each row ; Function to find the max height or the number of lines in the triangle pattern ; Driver Code
import java . util . * ; class GFG { static void triangle ( int n ) { int k = 2 * n - 2 ; int ch = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) System . out . print ( " ▁ " ) ; k = k - 1 ; for ( int j = 0 ; j <= i ; j ++ ) { System . out . print ( ch ++ + " ▁ " ) ; } System . out . println ( ) ; } } static int maxHeight ( int n ) { return ( ( ( int ) Math . sqrt ( 1 + 8.0 * n ) ) - 1 ) / 2 ; } public static void main ( String [ ] args ) { int N = 9 ; triangle ( maxHeight ( N ) ) ; } }
Number of ways in which N can be represented as the sum of two positive integers | Java implementation of the approach ; Function to return the number of distinct ways to represent n as the sum of two integers ; Driver code
class GFG { static int ways ( int n ) { return n / 2 ; } public static void main ( String args [ ] ) { int n = 2 ; System . out . println ( ways ( n ) ) ; } }
Number of ways to erase exactly one element in the Binary Array to make XOR zero | Java program to find the number of ways to erase exactly one element from this array to make XOR zero ; Function to find the number of ways ; Calculate the number of 1 ' s ▁ and ▁ 0' s ; Considering the 4 cases ; Driver code
class GFG { static int no_of_ways ( int a [ ] , int n ) { int count_0 = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) count_0 ++ ; else count_1 ++ ; } if ( count_1 % 2 == 0 ) return count_0 ; else return count_1 ; } public static void main ( String [ ] args ) { int n = 4 ; int a1 [ ] = { 1 , 1 , 0 , 0 } ; System . out . println ( no_of_ways ( a1 , n ) ) ; n = 5 ; int a2 [ ] = { 1 , 1 , 1 , 0 , 0 } ; System . out . println ( no_of_ways ( a2 , n ) ) ; n = 5 ; int a3 [ ] = { 1 , 1 , 0 , 0 , 0 } ; System . out . println ( no_of_ways ( a3 , n ) ) ; n = 6 ; int a4 [ ] = { 1 , 1 , 1 , 0 , 0 , 0 } ; System . out . println ( no_of_ways ( a4 , n ) ) ; } }
Minimum absolute difference between N and any power of 2 | Java implementation of the approach ; Function to return the highest power of 2 less than or equal to n ; Function to return the smallest power of 2 greater than or equal to n ; Function that returns the minimum absolute difference between n and any power of 2 ; Driver code
import java . util . * ; class GFG { static int prevPowerof2 ( int n ) { int p = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ; return ( int ) Math . pow ( 2 , p ) ; } static int nextPowerOf2 ( int n ) { int p = 1 ; if ( ( n == 0 ) && ! ( ( n & ( n - 1 ) ) == 0 ) ) return n ; while ( p < n ) p <<= 1 ; return p ; } static int minDiff ( int n ) { int low = prevPowerof2 ( n ) ; int high = nextPowerOf2 ( n ) ; return Math . min ( n - low , high - n ) ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( minDiff ( n ) ) ; } }
Maximum possible number with the given operation | Java implementation of the approach ; Function to return the maximum possible integer that can be obtained from the given integer after performing the given operations ; For every digit ; Digits greater than or equal to 5 need not to be changed as changing them will lead to a smaller number ; The resulting integer cannot have leading zero ; Driver code
class GFG { static String maxInt ( char str [ ] ) { for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] < '5' ) { str [ i ] = ( char ) ( ( '9' - str [ i ] ) + '0' ) ; } } if ( str [ 0 ] == '0' ) str [ 0 ] = '9' ; String str2 = new String ( str ) ; return str2 ; } public static void main ( String [ ] args ) { String str = "42" ; System . out . println ( maxInt ( str . toCharArray ( ) ) ) ; } }
Find the ratio of number of elements in two Arrays from their individual and combined average | Java program to Find the Ratio of number of Elements in two Arrays from their individual and combined Average ; function to find the ratio of number of array elements ; calculating GCD of them ; make neumarator and denominator coprime ; Driver Code
class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void FindRatio ( int a , int b , int c ) { int up = Math . abs ( b - c ) ; int down = Math . abs ( c - a ) ; int g = gcd ( up , down ) ; up /= g ; down /= g ; System . out . println ( up + " : " + down ) ; } public static void main ( String [ ] args ) { int a = 4 , b = 10 , c = 6 ; FindRatio ( a , b , c ) ; } }
Maximum distance between two 1 's in Binary representation of N | Java program to find the Maximum distance between two 1 's in Binary representation of N ; Compute the binary representation ; if N is a power of 2 then return - 1 ; else find the distance between the first position of 1 and last position of 1 ; Driver code
class GFG { static int longest_gap ( int N ) { int distance = 0 , count = 0 , first_1 = - 1 , last_1 = - 1 ; while ( N != 0 ) { count ++ ; int r = N & 1 ; if ( r == 1 ) { first_1 = first_1 == - 1 ? count : first_1 ; last_1 = count ; } N = N / 2 ; } if ( last_1 <= first_1 ) { return - 1 ; } else { distance = ( last_1 - first_1 - 1 ) ; return distance ; } } public static void main ( String [ ] args ) { int N = 131 ; System . out . println ( longest_gap ( N ) ) ; N = 8 ; System . out . println ( longest_gap ( N ) ) ; N = 17 ; System . out . println ( longest_gap ( N ) ) ; N = 33 ; System . out . println ( longest_gap ( N ) ) ; } }
Check if it is possible to move from ( 0 , 0 ) to ( X , Y ) in exactly K steps | Java implementation of the approach ; Function that returns true if it is possible to move from ( 0 , 0 ) to ( x , y ) in exactly k moves ; Minimum moves required ; If possible ; Driver code
class GFG { static boolean isPossible ( int x , int y , int k ) { int minMoves = Math . abs ( x ) + Math . abs ( y ) ; if ( k >= minMoves && ( k - minMoves ) % 2 == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int x = 5 , y = 8 , k = 20 ; if ( isPossible ( x , y , k ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Check whether N is a Factorion or not | Java implementation of the above approach ; Function that returns true if n is a Factorion ; fact [ i ] will store i ! ; A copy of the given integer ; To store the sum of factorials of the digits of n ; Get the last digit ; Add the factorial of the current digit to the sum ; Remove the last digit ; Driver code
class GFG { static int MAX = 10 ; static boolean isFactorion ( int n ) { int fact [ ] = new int [ MAX ] ; fact [ 0 ] = 1 ; for ( int i = 1 ; i < MAX ; i ++ ) fact [ i ] = i * fact [ i - 1 ] ; int org = n ; int sum = 0 ; while ( n > 0 ) { int d = n % 10 ; sum += fact [ d ] ; n /= 10 ; } if ( sum == org ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 40585 ; if ( isFactorion ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Find the possible permutation of the bits of N | Java implementation of the approach ; Function that returns true if it is possible to arrange the bits of n in alternate fashion ; To store the count of 1 s in the binary representation of n ; If the number set bits and the number of unset bits is equal ; Driver code
import java . util . * ; class GFG { static int TOTAL_BITS = 32 ; static boolean isPossible ( int n ) { int cnt = Integer . bitCount ( n ) ; if ( cnt == TOTAL_BITS / 2 ) return true ; return false ; } static public void main ( String [ ] arr ) { int n = 524280 ; if ( isPossible ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Check if two Integer are anagrams of each other | Java implementation of the approach ; Function to update the frequency array such that freq [ i ] stores the frequency of digit i in n ; While there are digits left to process ; Update the frequency of the current digit ; Remove the last digit ; Function that returns true if a and b are anagarams of each other ; To store the frequencies of the digits in a and b ; Update the frequency of the digits in a ; Update the frequency of the digits in b ; Match the frequencies of the common digits ; If frequency differs for any digit then the numbers are not anagrams of each other ; Driver code
class GFG { static final int TEN = 10 ; static void updateFreq ( int n , int [ ] freq ) { while ( n > 0 ) { int digit = n % TEN ; freq [ digit ] ++ ; n /= TEN ; } } static boolean areAnagrams ( int a , int b ) { int [ ] freqA = new int [ TEN ] ; int [ ] freqB = new int [ TEN ] ; updateFreq ( a , freqA ) ; updateFreq ( b , freqB ) ; for ( int i = 0 ; i < TEN ; i ++ ) { if ( freqA [ i ] != freqB [ i ] ) return false ; } return true ; } public static void main ( String [ ] args ) { int a = 204 , b = 240 ; if ( areAnagrams ( a , b ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible | Java implementation of the approach ; Function to find the permutation of the first N natural numbers such that the sum of ( i % Pi ) is maximum possible and return the maximum sum ; Driver code ; Function call
class GFG { static int Max_Sum ( int n ) { return ( n * ( n - 1 ) ) / 2 ; } public static void main ( String [ ] args ) { int n = 8 ; System . out . println ( Max_Sum ( n ) ) ; } }
Check if the number formed by the last digits of N numbers is divisible by 10 or not | Java implementation of the approach ; Function that returns true if the number formed by the last digits of all the elements is divisible by 10 ; Last digit of the last element ; Number formed will be divisible by 10 ; Driver code
import java . util . * ; class GFG { static boolean isDivisible ( int arr [ ] , int n ) { int lastDigit = arr [ n - 1 ] % 10 ; if ( lastDigit == 0 ) return true ; return false ; } static public void main ( String [ ] arg ) { int arr [ ] = { 12 , 65 , 46 , 37 , 99 } ; int n = arr . length ; if ( isDivisible ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Count of Multiples of A , B or C less than or equal to N | Java implementation of the approach ; Function to return the gcd of a and b ; Function to return the count of integers from the range [ 1 , num ] which are divisible by either a , b or c ; Calculate the number of terms divisible by a , b and c then remove the terms which are divisible by both ( a , b ) or ( b , c ) or ( c , a ) and then add the numbers which are divisible by a , b and c ; Driver code
import java . util . * ; class GFG { static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static long divTermCount ( long a , long b , long c , long num ) { return ( ( num / a ) + ( num / b ) + ( num / c ) - ( num / ( ( a * b ) / gcd ( a , b ) ) ) - ( num / ( ( c * b ) / gcd ( c , b ) ) ) - ( num / ( ( a * c ) / gcd ( a , c ) ) ) + ( num / ( ( a * b * c ) / gcd ( gcd ( a , b ) , c ) ) ) ) ; } static public void main ( String [ ] arr ) { long a = 7 , b = 3 , c = 5 , n = 100 ; System . out . println ( divTermCount ( a , b , c , n ) ) ; } }
Array containing power of 2 whose XOR and Sum of elements equals X | Java implementation implementation of the above approach ; Function to return the required array ; Store the power of 2 ; while n is greater than 0 ; if there is 1 in binary representation ; Divide n by 2 Multiply p2 by 2 ; Driver code ; Get the answer ; Printing the array
import java . util . * ; class GFG { static Vector < Long > getArray ( int n ) { Vector < Long > ans = new Vector < Long > ( ) ; long p2 = 1 ; while ( n > 0 ) { if ( n % 2 == 1 ) ans . add ( p2 ) ; n >>= 1 ; p2 *= 2 ; } return ans ; } public static void main ( String [ ] args ) { int n = 15 ; Vector < Long > ans = getArray ( n ) ; for ( Long i : ans ) System . out . print ( i + " ▁ " ) ; } }
Find out the correct position of the ball after shuffling | Java implementation of the above approach ; Function to generate the index of the glass containing the ball ; Change the index ; Change the index ; Print the index ; Driver Code ; Storing all the shuffle operation
import java . io . * ; class GFG { static int M = 3 ; static int N = 2 ; static void getIndex ( int n , int shuffle [ ] [ ] ) { for ( int i = 0 ; i < 3 ; i ++ ) { if ( shuffle [ i ] [ 0 ] == n ) n = shuffle [ i ] [ 1 ] ; else if ( shuffle [ i ] [ 1 ] == n ) n = shuffle [ i ] [ 0 ] ; } System . out . println ( n ) ; } public static void main ( String [ ] args ) { int n = 3 ; int shuffle [ ] [ ] = { { 3 , 1 } , { 2 , 1 } , { 1 , 2 } } ; getIndex ( n , shuffle ) ; } }
Count the number of subsequences of length k having equal LCM and HCF | Java implementation for above approach ; Returns factorial of n ; Returns nCr for the given values of r and n ; Map to store the frequencies of each elements ; Loop to store the frequencies of elements in the map ; Using nCR formula to calculate the number of subsequences of a given length ; Driver Code ; Function calling
import java . util . * ; class GFG { static long fact ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static long nCr ( int n , int r ) { return fact ( n ) / ( 1 * fact ( r ) * fact ( n - r ) ) ; } static long number_of_subsequences ( int arr [ ] , int k , int n ) { long s = 0 ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } for ( Map . Entry < Integer , Integer > j : mp . entrySet ( ) ) { s = s + 1 * nCr ( j . getValue ( ) , k ) ; } return s ; } static public void main ( String [ ] arg ) { int arr [ ] = { 1 , 1 , 1 , 1 , 2 , 2 , 2 } ; int k = 2 ; int n = arr . length ; System . out . println ( number_of_subsequences ( arr , k , n ) ) ; } }
Find the sum of all possible pairs in an array of N elements | Java implementation of the approach ; Function to return the sum of the elements of all possible pairs from the array ; To store the required sum ; For every element of the array ; It appears ( 2 * n ) times ; Driver code
import java . util . * ; class GFG { static int sumPairs ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( arr [ i ] * ( 2 * n ) ) ; } return sum ; } static public void main ( String [ ] arg ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . println ( sumPairs ( arr , n ) ) ; } }
Minimum sum obtained from groups of four elements from the given array | Java implementation of the approach ; Function to return the minimum required sum ; To store the required sum ; Sort the array in descending order ; The indices which give 0 or 1 as the remainder when divided by 4 will be the maximum two elements of the group ; Driver code
import java . util . * ; class GFG { static int minSum ( Integer arr [ ] , int n ) { int sum = 0 ; Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 4 < 2 ) sum = sum + arr [ i ] ; } return sum ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 1 , 1 , 10 , 2 , 2 , 2 , 1 } ; int n = arr . length ; System . out . println ( minSum ( arr , n ) ) ; } }
Count of triples ( A , B , C ) where A * C is greater than B * B | Java implementation of above approach ; function to return the count of the valid triplets ; Driver Code ; function calling
import java . util . * ; class GFG { static long countTriplets ( int A , int B , int C ) { long ans = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { for ( int j = 1 ; j <= B ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( i * k > j * j ) ans ++ ; } } } return ans ; } public static void main ( String [ ] args ) { int A = 3 , B = 2 , C = 2 ; System . out . println ( countTriplets ( A , B , C ) ) ; } }
Count of triples ( A , B , C ) where A * C is greater than B * B | Java implementation of the approach ; Counts the number of triplets for a given value of b ; Count all triples in which a = i ; Smallest value j such that i * j > B2 ; Count all ( i , B2 , x ) such that x >= j ; count all ( x , B2 , y ) such that x >= j this counts all such triples in which a >= j ; As all triples with a >= j have been counted reduce A to j - 1. ; Counts the number of triples that satisfy the given constraints ; GetCount of triples in which b = i ; Driver Code ; Function calling
import java . util . * ; class GFG { static long getCount ( int A , int B2 , int C ) { long count = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { long j = ( B2 / i ) + 1 ; if ( C >= j ) count = ( count + C - j + 1 ) ; if ( A >= j && C >= i ) count = ( count + ( C - i + 1 ) * ( A - j + 1 ) ) ; if ( A >= j ) A = ( int ) ( j - 1 ) ; } return count ; } static long countTriplets ( int A , int B , int C ) { long ans = 0 ; for ( int i = 1 ; i <= B ; i ++ ) { ans = ( ans + getCount ( A , i * i , C ) ) ; } return ans ; } public static void main ( String [ ] args ) { int A , B , C ; A = 3 ; B = 2 ; C = 2 ; System . out . println ( countTriplets ( A , B , C ) ) ; } }
Summation of floor of harmonic progression | Java implementation of the approach ; Function to return the summation of the given harmonic series ; To store the summation ; Floor of sqrt ( n ) ; Summation of floor ( n / i ) ; From the formula ; Driver code
class GFG { static long getSum ( int n ) { long sum = 0 ; int k = ( int ) Math . sqrt ( n ) ; for ( int i = 1 ; i <= k ; i ++ ) { sum += Math . floor ( n / i ) ; } sum *= 2 ; sum -= Math . pow ( k , 2 ) ; return sum ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( getSum ( n ) ) ; } }
Count of distinct remainders when N is divided by all the numbers from the range [ 1 , N ] | Java implementation of the above approach ; Function to return the count of distinct remainders that can be obtained when n is divided by every element from the range [ 1 , n ] ; If n is even ; If n is odd ; Driver code
class GFG { static int distinctRemainders ( int n ) { if ( n % 2 == 0 ) return ( n / 2 ) ; return ( 1 + ( n / 2 ) ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( distinctRemainders ( n ) ) ; } }
Count total unset bits in all the numbers from 1 to N | Java implementation of the approach ; Function to return the count of unset bits in the binary representation of all the numbers from 1 to n ; To store the count of unset bits ; For every integer from the range [ 1 , n ] ; A copy of the current integer ; Count of unset bits in the current integer ; If current bit is unset ; Driver code
class GFG { static int countUnsetBits ( int n ) { int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int temp = i ; while ( temp > 0 ) { if ( temp % 2 == 0 ) { cnt = cnt + 1 ; } temp = temp / 2 ; } } return cnt ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( countUnsetBits ( n ) ) ; } }