About 88,300 results
Open links in new tab
  1. How to sum digits of an integer in java? - Stack Overflow

    Nov 24, 2014 · I am trying to develop a program in Java that takes a number, such as 321, and finds the sum of digits, in this case 3 + 2 + 1 = 6. I need all the digits of any three digit number …

  2. java - How to write a recursive method to return the sum of digits …

    Mar 14, 2012 · public int getsum (int n){ int num = 23456; int total = 0; while (num != 0) { total += num % 10; num /= 10; } } The problem is that i cant/know how to change this into a recursive …

  3. Find Sum of digits for given number in java 8? - Stack Overflow

    May 19, 2021 · Suppose Example1: number is 37 Sum of numbers is 3+7= 10 Ex2: Number is 1000 Sum of numbers is 1+0+0+0 = 1. My first approach was converting number to string and …

  4. java - sum of digits of an integer - Stack Overflow

    Oct 14, 2020 · Enter an integer: 12a34 Exception in thread "main" java.lang.IllegalArgumentException: 12a34 is not a whole number. at …

  5. Sum of Digits in Java - Stack Overflow

    sum += t*t*t; number = number/10; } System.out.println("The sum of the cubes of the digits is:" +sum); } } Okay so I'm using a while loop. For part B which is to modify to determine what …

  6. How to sum a list of integers with java streams? - Stack Overflow

    May 8, 2015 · How do you sum to a particular value? for example, you have a list of integers but you want to sum till you get the value 20.

  7. How do you find the sum of all the numbers in an array in Java?

    Dec 29, 2010 · I'm having a problem finding the sum of all of the integers in an array in Java. I cannot find any useful method in the Math class for this.

  8. java - Reduce sum of digits recursively down to one digit number ...

    May 28, 2019 · How do I make a function return the sum of all digits until it becomes a 1 digit number, using recursion? I was able to make a function that gets the sum of all digits, but cant …

  9. java - The sum of all odd digits of an input - Stack Overflow

    Sep 11, 2020 · How to compute the sum of all 'odd digits of an input' using 'loop'. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.) I can't quite figure out how to do that, …

  10. how to calculate the sum of digits for a number in java?

    Dec 27, 2014 · 0 i have a small function that ask user to enter a positive number than give him the reverse and calculate the sum of its digits. the first part of code work fine but the sum of digits …