fork download
  1. /* package whatever; // count no of 1's in binary reprsentation/
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int a=22;
  13. // int b=5;
  14. //String b="god";
  15. int tt=represent(a);
  16. // int[][] matrix = {
  17. // {1, 2, 3},
  18. // {4, 5, 6},
  19. //{7, 8, 9}
  20. //};
  21. System.out.println((tt));
  22. //swap(a,b);
  23. }
  24. public static int represent(int n){
  25. int count=0;
  26. while(n>0){
  27. if((n&1)==1){
  28. count++;
  29. }
  30. n=n>>1;
  31. }
  32. return count;
  33. }
  34. }
Success #stdin #stdout 0.07s 52448KB
stdin
Standard input is empty
stdout
3