Pages

Wednesday, 8 June 2016

Print Even or Odd without using conditional statement in Java



public classEvenOddWoCondition {

     /**
      * Return even odd result.
      * @param number
      * @return even or odd.
      */
     private static String getEvenOddRest(int number) {
           String[] array  = {"even","odd"};

           int index = number%2;

           returnarray[index];
     }

     public static voidmain(String[] args) {
           int number = 10;
           String result = getEvenOddRest(number);
           System.out.println(result);
     }
}

No comments:

Post a Comment