public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case int a = in.nextInt(); int count =0; // 进行与运算 for (int i=0;i<32;i++) { int n=(int)Math.pow(2,i); if ((n&a)==n) { count++; } } System.out.print(count); } } } 我感觉我这种解法思路更优
点赞

相关推荐

09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
看网上说华为1145每个人都会收到,请问华为1145是什么东西
老黑奴:面试如果通过当天晚上11:45会收到面试反馈邮件
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务