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

}

}

Re: pseudo code and algorithms

Do you have any specific questions about the assignment you posted?

What have you done so far?

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!

Re: pseudo code and algorithms

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

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

Re: pseudo code and algorithms

Quote:

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.

Re: pseudo code and algorithms