• + 0 comments

    Java

        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    
            int n = Integer.parseInt(bufferedReader.readLine().trim());
            
            StringBuffer strBase10 = new StringBuffer();
            int maxOnes = 0;
            int onesFound = 0;
            
            while(n>=1){
                double x = n;
                if(x%2==0){
                    strBase10.append("0");
                    if(onesFound>maxOnes){
                        maxOnes = onesFound;
                    }
                    onesFound = 0;
                }else{
                    onesFound++;
                    strBase10.append("1");
                }
                n = n/2;             
            }
            
            if(onesFound>maxOnes){
                maxOnes = onesFound;
            }
           
           System.out.println(maxOnes);
            
        }