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 4 of 4

Thread: sum of arrays and printing even and odd numbers in the array

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sum of arrays and printing even and odd numbers in the array

    Call a method that computes the sum of the elements of the array. The header for this method is

    public static int sumData(int num, int[] iArr, boolean DEBUG)

    After the returning from the sumData method you will need to print out the int returned by the sumData method.

    Then you will call a method that will print only the even numbers stored in the array. The header for this method is

    public static void printEven(int num, int[] iArr, boolean DEBUG)

    Then you will call a method that will print out the odd numbers stored in the array. The header for this method is

    public static void printOdd(int num, int[] iArr, boolean DEBUG)
    Detailed explanation: YES
    Specific requirements:
    The data in the arrays are generated at random and the array should be no bigger than 30. Pseudorandom integers should be between 10 and 90.
    The program's output must be similar to this:

    DEBUG
    The location of array being added to the sum is 0.
    The number added to sum is 95.
    The current sum is 95.

    DEBUG
    The location of array being added to the sum is 1.
    The number added to sum is 28.
    The current sum is 123.

    DEBUG
    The location of array being added to the sum is 2.
    The number added to sum is 47.
    The current sum is 170.

    DEBUG
    The location of array being added to the sum is 3.
    The number added to sum is 89.
    The current sum is 259.

    DEBUG
    The location of array being added to the sum is 4.
    The number added to sum is 98.
    The current sum is 357.

    The sum of the array is 357.

    Even numbers in the array are:

    DEBUG
    The nummber in array location 0 is 95.

    DEBUG
    The nummber in array location 1 is 28.

    DEBUG
    The number is even.

    intArr[1] = 28

    DEBUG
    The nummber in array location 2 is 47.

    DEBUG
    The nummber in array location 3 is 89.

    DEBUG
    The nummber in array location 4 is 98.

    DEBUG
    The number is even.

    intArr[4] = 98

    Odd numbers in the array are:

    DEBUG
    The nummber in array location 0 is 95.

    DEBUG
    The number is odd.

    intArr[0] = 95

    DEBUG
    The nummber in array location 1 is 28.

    DEBUG
    The nummber in array location 2 is 47.

    DEBUG
    The number is odd.

    intArr[2] = 47

    DEBUG
    The nummber in array location 3 is 89.

    DEBUG
    The number is odd.

    intArr[3] = 89

    DEBUG
    The nummber in array location 4 is 98.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: sum of arrays and printing even and odd numbers in the array

    Do you have a question? Do you have some code that you are having a problem with?
    Please post the code with your comments/questions about your code.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: sum of arrays and printing even and odd numbers in the array

    Sorry about that! I need help completing it, I'm not quite sure how to add the sum of the array, or print out the even and odd numbers. My code needs to be similar to the DEBUG example given

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: sum of arrays and printing even and odd numbers in the array

    There are many people here that will help you write your code. You need to provide the effort to figure out your assignment and write some code. When you have problems, post them here.
    Start with a simple skeleton and add to it little by little.
    First you need a class with a main method and a definition for the method you are to write.
    Then work on what that method is to do.
    how to add the sum of the array
    Do you know how to index the elements in an array?
    Do you know how to write a for loop?
    For a simple start, write a for loop that prints out the contents of the array, one element on a line.

Similar Threads

  1. Printing out numbers from an Array.
    By djl1990 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 13th, 2011, 12:03 PM
  2. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  3. Conversions of Numbers in Arrays
    By KiwiFlan in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 1st, 2010, 07:59 PM
  4. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM
  5. Printing a Histogram Help - Arrays
    By Mock26 in forum Collections and Generics
    Replies: 1
    Last Post: June 4th, 2009, 04:49 AM