Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* University of Malaya
- WIX 1002 - Fundamental of Programming
- Final Exam Sem 1 Year 2015/16
- Question 1 of 5
- Project name : "1516Q1.java"
- */
- package pkg1516q1;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- int[] num = {34,15,12,27,74,23};
- int cnt = 0;
- for(int i = 0;i<num.length;i++)
- if(isEven(num[i]))
- cnt++;
- System.out.println("The number of even number is " + cnt);
- System.out.println("The sum of the array is "+getTotal(num));
- }
- public static boolean isEven(int a){
- if(a%2==0)
- return true;
- else
- return false;
- }
- public static int getTotal(int[] a){
- int total=0;
- for(int i=0;i<a.length;i++)
- total+=a[i];
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement