andy6804tw
7/16/2016 - 2:10 PM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2679 這提示輸入時進位整數顯示二進位中有幾個一,Integer.bitCount()剛好符合要求

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2679 這提示輸入時進位整數顯示二進位中有幾個一,Integer.bitCount()剛好符合要求

import java.util.*;  
  
public class Main {  
  
    public static void main(String[] args) {  
        Scanner scn = new Scanner(System.in);  
        int n=scn.nextInt();  
        System.out.printf("The number of bits is %d.\n",Integer.bitCount(n));  
          
    }  
    	/* 
    題目:[C_MM108-易] 位元計數器
    作者:1010
    時間:西元 2016 年 7 月 */
}