Odd or Even?(codewars-java9)

Given an array of numbers (a list in groovy), determine whether the sum of all of the numbers is odd or even.

Give your answer in string format as 'odd' or 'even'.

If the input array is empty consider it as: [0] (array with a zero).


public class Codewars {

  public static String oddOrEven (int[] array) {

  int sumNum=0;

    String num;

    for(int i =0;i

        sumNum=sumNum+array[i];

        }

        if(sumNum %2 ==0){

            num="even";

        }else{

            num="odd";

        }

      return num;

  }

}


https://www.codewars.com/kata/5949481f86420f59480000e7/train/java

你可能感兴趣的:(Odd or Even?(codewars-java9))