Posted by Adam Johnson on Tuesday, November 15, 2011 at 2:50am.
I have written function called count where the count function take in one parameter and the parameter is a array of number. The problem I having is how do i return the numbers of negative elements, zeros, and values greater than zeros in the given array. I don't understand how the switch statement are suppose to implement it.
You are probably best to post the method so far. However, switch statements are shorthands for a group of if statements that all relate to the same quantity as:
if (x == 0) doSomething0();
else if (x == 1) doSomething1();
else if (x == 2) doSomething2();
else if (x == 3) doSomething3();
else if (x == 4) doSomething4();
So in your case you need to read the value from the array called numbers,
for (int counter=0, counter<numbers.length, n++)
// now use the if statements to count how many of each type there are in the array. For clarity you will need to declare three variables for number of negatives, positives and zeros. For example
then use the switch statements to count each of the tree types.
Answer This Question
More Related Questions
- programming - I really need help in this it makes me confuse.I should make a ...
- computer science - 9.10: Reverse Array Write a function that accepts an int ...
- assembler language - write an assembly language subordinate count according to ...
- SQL - 1- A SQL statement is needed to create a stored procedure that has one ...
- computer science - Im trying to create an arraylist that's sorted but I have no ...