lol the code works and that all that matters
Type: Posts; User: Delstateprogramer
lol the code works and that all that matters
Thank you for your help everyone i figured the problem out heres the code i used
public static int addDigits(int number)
{
if(number<10)
{
sum=number+sum;
}
else
Tried this code and it didnt work
if(number<10)
{
return number;
}
else
{
return (number%10)+((addDigits(number/10)));
Ok thx ill try that out
how do i save the prior digits to add them up at the end becuz here they keep changing and are not saved so they cant be added at the end
The user should be able to enter any integer and the program should output the sum of the digits in the integer.
I didnt intend for it to be a number 1 through 99. It would not matter what the user put in. and yes it would add the digits in an integer. Heres an example.
If the user entered the integer 223...
thats the new code but yea its a logical error in there somewhere
public class AddEmUp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Enter an integer:");
...
yes thats exactly it and I fear i thought i got it but i didnt still need some help lol
Nvm all i got it
Changed my mind not gonna use an array, ive decided to do something like this but its not really working and i kno why but i dnt know how to change itm
while(number>10)
{
digit=number%10;
sum...
this program is supposed to add up the integers in a number entered by a user and print out the sum. i got the easy part down.
if(number<10)
{
sum=number;
}
for the next part i was...