Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java program to find the sum of all the digits in the inputted number

long number, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter any DIGIT number: ");
number = sc.nextLong();
sc.close();
// For Logic for adding all digits in the given number
for (sum = 0; number != 0; number /= 10) {
	sum += number % 10;
	}
System.out.println("ForLoop Sum of ALL digits: " + sum);
 
PREVIOUS NEXT
Tagged: #Java #program #find #sum #digits #inputted #number
ADD COMMENT
Topic
Name
1+5 =