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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: pseudo code and algorithms

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question 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
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: pseudo code and algorithms

    Do you have any specific questions about the assignment you posted?
    What have you done so far?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: pseudo code and algorithms

    If the number is in a String, the String class has methods for accessing each character in the String.
    If you don't understand my answer, don't ignore it, ask a question.

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

    oonagh (December 3rd, 2012)

  6. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: pseudo code and algorithms

    ok thanks

Similar Threads

  1. i need explanation in pseudo code
    By abood1190 in forum Loops & Control Statements
    Replies: 7
    Last Post: June 20th, 2012, 11:02 AM
  2. Video player with pseudo streaming
    By Wessel in forum AWT / Java Swing
    Replies: 0
    Last Post: April 25th, 2012, 05:06 PM
  3. pseudo Code Help
    By shamil max in forum Java Theory & Questions
    Replies: 1
    Last Post: March 27th, 2012, 09:08 AM
  4. HELP WITH PSEUDO CODE
    By pronk123 in forum Member Introductions
    Replies: 0
    Last Post: December 14th, 2010, 09:30 AM
  5. Pseudo code of insertion sort linked list
    By sungirl in forum Algorithms & Recursion
    Replies: 1
    Last Post: May 23rd, 2010, 09:25 AM