//this
method will return the sum of all even numbers(except 8) in array
public
int evenSumMinusEight(int[] array)
{
int sum=0;
for(int i=0; i<array.length;i++)
{
if(array[i]!=8&&array[i]%2==0)
sum=sum+array[i];
}
return sum;
Write
the LotteryTicket method search(), as started below. search() will receive an
integer and determine if that integer is contained in the array instance
variable numberList.
Assuming numberList
contains [1,2,3,4,5,6,7,8,9.10]
The call search(34)
would return false
as
34 is not contained the list.
The call search(3)
would return true
as
3 is contained the list.
The call search(4)
would return true
as
4 is contained the list.
/** @param
val is a positive non-decimal value
* Precondition
: val >= 1 and val <= 50
* @return true if val is contained in numberList
*
@return false if val is not contained in numberList
*/
private boolean search(int val)
{
for(int item : numberList)
{
if(item
== val)
return true;
}
return false;
}
No comments:
Post a Comment