입력받는 X의 값을 2진수로 표현하여 1의 개수 카운터해줬다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
public class Main1094_{
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int X = Integer.parseInt(br.readLine());
        String str = Integer.toBinaryString(X);
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) =='1') {
                count++;
            }
        }
        System.out.println(count);
    }//end of main
}//end of class
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

+ Recent posts