You are viewing a single comment's thread. Return to all 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); }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Java