0

Program to enter an integer or double and add all the numbers in java

Can you give me any keyword or ideas from which i can create a program to enter an integer or double number and add them all? E.g. 360 = 3+6+0=9

20th May 2021, 11:02 AM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar
6 ответов
+ 3
Take input as string, divide it into characters, convert each character to integer if possible (try/catch), calculate sum
20th May 2021, 12:21 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 3
Shikaki ira K Or you can use this int n=360; int s=0; while(n>0){ int d=n%10; s+=d; n/=10;}
20th May 2021, 12:48 PM
Atul [Inactive]
+ 1
post your code
20th May 2021, 11:04 AM
Atul [Inactive]
+ 1
Post your attempt
20th May 2021, 11:04 AM
Atul [Inactive]
+ 1
So complete the course and then try again
20th May 2021, 11:23 AM
Atul [Inactive]
0
Atul , i have got no any knowledge about this thing and i don't have no any keyword or idea to do it. So I haven't started my code yet.
20th May 2021, 11:20 AM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar