how to find odd and even numbers in array in javascript code example
Example 1: how to find even and odd numbers in javascript
<!DOCTYPE html>
<html>
<body>
<script>
var num = 5;
document.write("Number = "+num+"<br>");
if(num % 2 == 0) {
document.write('Number is even!');
} else {
document.write('Number is odd!');
}
</script>
</body>
</html>
Example 2: get odd number in array
public int[] findEvens() {
int numberEvens = 0;
for (int i = 0; i < numbers.length; i++) {
if (i % 2 == 0) {
numberEvens++;
}
}
Example 3: get odd number in array
public int[] findEvens() {
int numberEvens = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 == 0) {
numberEvens++;
}
}