Check the given number is odd or even





Test cases:

Test cases Expected Result
testOddEven(12) even OK
testOddEven(3) odd OK
testOddEven(-55) odd OK

Java solution:

package test;

public class Program2 {
	
	public static void main(String[] args) {
		Program2.testOddEven(12);
		Program2.testOddEven(3);
		Program2.testOddEven(-55);
	}
	
	public static String testOddEven(int num){
		if (num % 2 == 0) {
			return "even";
		}
		return "odd";
	}
}

Javascript solution:

const testOddEven = (num) => {
    if (num % 2 === 0) {
        return 'even';
    }
    return 'odd';
}

console.log(testOddEven(12)); //even
console.log(testOddEven(3)); //odd
console.log(testOddEven(-55)); //odd

 

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply