Skip to main content

Posts

Showing posts with the label Day 29: Bitwise AND Hackerrank Solution in Java

Day 29: Bitwise AND Hackerrank Solution Java

 Day 29: Bitwise AND  For Explanation Check Video: Sample Input STDIN Function ----- -------- 3 T = 3 5 2 N = 5, K = 2 8 5 N = 8, K = 5 2 2 N = 8, K = 5 Sample Output 1 4 0 Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'bitwiseAnd' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER N      *  2. INTEGER K      */      public   static   int  bitwiseAnd( int  N,  int  K) {      // Write your code here      int  res =  0 ;      for ( int  i= 1 ;i<=N;i++){ //1          for ( int  j=i+ 1 ;j<=N;j++){              int  ans = i&j; //