Array - Exercise 1
class Tester{
public static int calculateSumOfEvenNumbers(int[]numbers){
int sum=0;
for(int i=0;i<numbers.length;i++)
{
int a=numbers[i]%2;
if(a==0)
{
sum=sum+numbers[i];
}
}
returnsum;
}
public static void main(String[]args){
int[]numbers={68,79,86,99,23,2,41,100};
System.out.println("Sum of even numbers: "+calculateSumOfEvenNumbers(numbers));
}
}
No comments:
Post a Comment