I had quiz today in my IB CS course, and I had a question I could not understand, I will try to stated as closed as possible.

"There is an array of integers which holds an unknown amount of integers but it's not bigger than a 100.
if a = negative integers
b= non negative even integers
c= odd integers

There is a method which returns all of the non negative even integers. The method is already started below

nonNegative(int[] original){
missing code...
if(){
}
else(){
}"

## All 5 Replies

You did not finished question...

I had quiz today in my IB CS course, and I had a question I could not understand, I will try to stated as closed as possible.

"There is an array of integers which holds an unknown amount of integers but it's not bigger than a 100.
if a = negative integers
b= non negative even integers
c= odd integers

There is a method which returns all of the non negative even integers. The method is already started below

nonNegative(int[] original){
missing code...
if(){
}
else(){
}"

That was very embarassing.

There method has to return b or how many non negative even intergers where found.

so, the method has to return b ...
how would you solve this?

so, the method has to return b ...
how would you solve this?

Well I'm thinking about first making sure the interger is bigger than 0

``````int currentInt>0
``````

and then storing that in an array

``````for(int i=0;i <100;i++)
{
if(currentElement.equals(currentElement[i]>100)==true){
tempArray[i]= currentElement[i];}
}
else{
system.out.println("Done");
}
}
``````

Finally

``````for(int o =0;o<tempArray[].length;o++){
int b;
if(tempArray[o]/2 = evenNumber) // I Don't know how to make the program find out if it's an even number. I'm guessing if it can be divided by 2 then obviously it's an even number.
{
b++;
}
else{System.out.println("Done");
}
}
``````

Sorry if it's not very understandable, I have never done pseudocode before

There is a very handy maths operation called modulo. Which finds the remainder of division of one number by another. So, what do all even numbers have in common? Yes, they have a remainder of 0 when divided by 2.

The modulo operator is: %

``````for(int i=0; i< aray.length;i++)
{
if(array[i]%2 == 0)
{
newArray[i] = array[i];
}

}``````

Etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.