6.求int型正整数在内存中存储时1的个数
来源:互联网 发布:linux getconfig 编辑:程序博客网 时间:2024/06/04 19:09
题目描述
输入一个int型的正整数,计算出该int型数据在内存中存储时1的个数。
整数在内存中存储是按二进制存储的,所以要转成二进制
import java.util.Scanner;public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int input = sc.nextInt(); int count = count1(input); System.out.println(count); } } public static int count1(int input){ int count=0; while((input/2)!=0){ if(input%2==1){ count++; } input /=2; } count++; return count; }}
阅读全文
0 0
- 6.求int型正整数在内存中存储时1的个数
- Java-NowCoder-求int型正整数在内存中存储时1的个数
- nowcoder--求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- 【华为OJ15】求int型正整数在内存中存储时1的个数
- 14:求int型正整数在内存中存储时1的个数
- 华为oj之求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- [编程题]求int型正整数在内存中存储时1的个数
- 华为OJ:求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- 15——求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- 【华为OJ】求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- 华为——求int型正整数在内存中存储时1的个数
- nowcoder华为机试:求int型正整数在内存中存储时1的个数
- 求int型正整数在内存中存储时1的个数
- 神器Ngrok映射外网
- 案例——天气预报 菜鸟级别的我
- python爬虫(threading.Condition())
- 厦门蓝天怎么样?
- 2018考研政治——马原2
- 6.求int型正整数在内存中存储时1的个数
- C语言字符串处理函数
- PHP删除HTMl标签的解决方法
- 资源下载类网站-如何判定该资源是否是最新资源
- ONOS编程系列(二)命令行命令与服务开发
- qt工程新增的UI如何手工调用现有的prc文件中的图片资源
- Mysql 如何设置字段自动获取当前时间
- PHP错误提示处理
- 【Java8源码分析】并发包-CountDownLatch