Free Puzzle Questions with Answer using Java, C#, JavaScript and PHP

Java Quiz - Difference Of Odd And Even Sum

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package differenceofoddandevensum;

/**
 *
 * @author Bereket
 */
public class DifferenceOfOddAndEvenSum {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int[] sampleData = {3, 3, 4, 4};
        
        int result = Calculate(sampleData);
        
        System.out.println(String.valueOf(result));
    }
    
    static int Calculate(int[] givenArray){
        int sumOfOddNumbers = 0; //X - initialize sum of odd numbers
        int sumOfEvenNumbers = 0; //Y - initialize sum of even numbers
        
        for(int i=0; i< givenArray.length; i++){
            if((givenArray[i]%2)==0){//the current value if EVEN
                //add the current value to the sum of even numbers
                sumOfEvenNumbers = sumOfEvenNumbers + givenArray[i];
            }
            else{//the current value if ODD
                //add the current value to the sum of odd numbers
                sumOfOddNumbers = sumOfOddNumbers + givenArray[i];
            }
        }
        
        //return the difference of sum of odd numbers and sum of even numbers
        return (sumOfOddNumbers - sumOfEvenNumbers);
    }
    
}