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.
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.
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
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.
Quote:
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.