Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: pseudo code and algorithms

1. ## pseudo code and algorithms

Using Pseudo code, design an algorithm that can sum the digits of an integer in
the range 100-999. For example, given a number 734, the answer would be 7 + 3
+ 4, which equals 14. Given 103 the sum would be 1 + 0 + 3, which equals 4.
Hint: in order to extract each digit (units, tens, hundreds etc.) from a given
number, think about using the division (/) and, or modulus of that number by
10 or multiples of 10.
Additional marks are available for an algorithm that can deal with any size of
number.
2. Complete the outline Java class below by,
Using the algorithm above to implement the sumOfDigits value method, which
accepts a number as a parameter and returns the sum of its digits.
Implement the main method that should prompt the user to input an integer
number then print the number and a message stating whether the sum of its
digits is equal to 10. Note - the user should be forced to enter a number between
100 and 999 inclusive. Sample program executions might look as follows

Input Number: 730
The sum of the digits of 730 is 10 and is equal to 10.

Input Number: 198
The sum of the digits of 198 is 18 and is NOT equal to 10.

// Sample outline class.
public class Sum
{
public static int sumOfDigits int number)
{
// complete method
}
public static void main(String[] args)
{
// complete method
}
}  Reply With Quote

3. ## Re: pseudo code and algorithms

Do you have any specific questions about the assignment you posted?
What have you done so far?  Reply With Quote

4. ## Re: pseudo code and algorithms

how do you separate the 3 numbers?
i am new to java and really haven't a clue haven't attempted the question yet!  Reply With Quote

5. ## Re: pseudo code and algorithms

If the number is in a String, the String class has methods for accessing each character in the String.  Reply With Quote

6. ## The Following User Says Thank You to Norm For This Useful Post:

oonagh (December 3rd, 2012)

7. ## Re: pseudo code and algorithms

can you explain that in more detail please?

public class Sum
{
public static int sumOfDigits int number)
{
// complete method
}
public static void main(String[] args)
{
// complete method
}
}

that's the code started but i don't know what methods to put in  Reply With Quote

8. ## Re: pseudo code and algorithms

i don't know what methods to put in
First you need to make a list in pseudo code of what the program will do. When you have the list of steps, then use that to write the code.  Reply With Quote

9. ## Re: pseudo code and algorithms

ok thanks   Reply With Quote