当前位置:网站首页>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 :

 Insert picture description here

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201234082001.html