zoukankan      html  css  js  c++  java
  • 统计2的N次方的数的个数

    package huawei;

    import java.util.Scanner;

    public class TestHuaWei {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int nCount = 0;
    try {
    if (in.hasNextLine()) {
    String line = in.nextLine();

    if (line != null && line.trim().length() > 128) {
    System.out.println("输出错误");
    }

    String iArray [] = line.split(",");

    for (int i = 0, size = iArray.length; i < size; i++) {

    int num = Integer.valueOf(iArray[i]).intValue();
    if (num == 1) {
    nCount ++;
    } else {
    if ((num & (num - 1)) == 0) {
    nCount ++;
    }
    }

    }
    }
    }catch(Exception e) {
    System.out.println("输入错误");
    } finally {
    if (in != null) {
    in.close();
    }
    }

    System.out.println(nCount);




    }

    }

  • 相关阅读:
    cpuset
    top
    path-lookup
    strace
    IDR算法[原理]
    cgroup
    转载
    std::reverse_iterator::base
    可重入、不可重入
    chromium code 中 普遍使用的 C++11 语法
  • 原文地址:https://www.cnblogs.com/tiny-kong/p/4055193.html
Copyright © 2011-2022 走看看