当前位置:网站首页>Enter an integer with any number of bits, and output the sum of each bit of the number. For example: 1234 – > 10
Enter an integer with any number of bits, and output the sum of each bit of the number. For example: 1234 – > 10
2022-06-25 07:14:00 【Python's path to becoming a God】
Code :
package com.homework;
import java.util.Scanner;
public class Bit_Sum {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print(" Enter an integer with any number of digits :");
long num = input.nextLong();
long a=0;
while(num>0) {
a += num%10;
num /= 10;
}
System.out.print(" Sum of each digit of the number :"+a);
}
}
Running results :
边栏推荐
- How do I get red green blue (RGB) and alpha back from a UIColor object?
- 我与CSDN的一年时光及大学经验分享
- 有了 MySQL 为什么要用 NoSQL?
- Flexbox on ie11: stretching images for no reason- Flexbox on IE11: image stretched for no reason?
- Capable people never complain about the environment!
- Non-contact infrared temperature measurement system for human body based on single chip microcomputer
- [ros2] Why use ros2? Introduction to ros2 system characteristics
- Kubernetes cluster dashboard & kuboard installation demo
- How to get the difference between two dates rounded to hours
- Bcrypt password encryption kalrry
猜你喜欢
爱情️终结者
Event registration Apache pulsar x kubesphere online meetup hot registration
Understand ZBrush carving software and game modeling analysis
Hongmeng learning notes: creating layouts using XML
48 张图 | 手摸手教你微服务的性能监控、压测和调优
Want to self-study SCM, do you have any books and boards worth recommending?
Practice of hierarchical management based on kubesphere
有了 MySQL 为什么要用 NoSQL?
【工具分享】一款颜值与技能并重的软件
【一起上水硕系列】Day 5
随机推荐
Analysis on the scale of China's smart airport industry in 2020: there is still a large space for competition in the market [figure]
Event registration Apache pulsar x kubesphere online meetup hot registration
Efficient exploration | an application practice of ES geographical location query
48 张图 | 手摸手教你微服务的性能监控、压测和调优
【C语言】给字符串增加分隔符
[acnoi2022] the structure of President Wang
活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
In depth analysis of Apache bookkeeper series: Part 3 - reading principle
Love Terminator
有了 MySQL 为什么要用 NoSQL?
TorchServe避坑指南
Understand ZBrush carving software and game modeling analysis
【2022黑马程序员】SQL优化
100 times larger than the Milky way, Dutch astronomers found mysterious objects in deep space
Can we use function pointers in go- Can we have function pointers in Go?
Flexbox on ie11: stretching images for no reason- Flexbox on IE11: image stretched for no reason?
How to recover redis data from snapshot(rdb file) copied from another machine?
3632. Binary sum
Non-contact infrared temperature measurement system for human body based on single chip microcomputer
Three laws of go reflection