+15  A: 

An odd number is not evenly divisible by two. All you need to know is are there two odd numbers in the set. Just check to see if each number mod 2 is non-zero. If so it is odd. If you find two odd numbers then you can multiply those and get another odd number.

Note: an odd number multiplied by an even number is always even.

tvanfosson
+5  A: 

The product of two integers will be odd only if both integers are odd. So, to solve this problem, just scan the array once and see if there are two (or more) odd integers.

EDIT: As others have mentioned, you check to see if a number is odd by using the modulus (%) operator. If N % 2 == 0, then the number is even.

Bill the Lizard
7 + 3 = 10. I think you meant the product of two integers is even only if both integers are odd.
David Robbins
The product is the result of multiplication. The sum is the result of addition.
Bill the Lizard
A: 

You can test for evenness (or oddness) by using the modulus.

i % 2 = 0 if i is even; test for that and you can find out if a number is even/odd

masher
+3  A: 

Properties worth thinking about:

  • Odd numbers are not divisible by 2
  • Any number multiplied by an even number is even

So you can re-state the question as:

Does the array contain at least two integers that are not divisible by 2?

Which should make things easier.

Greg Beech
A: 

A brute force algorithm:

public static boolean hasAtLeastTwoOdds(int[] args) {
    int[] target = args; // make defensive copy
    int oddsFound;
    int numberOddsSought = 2;

    for (int i = 0; i < target.length; i++) {
        if (target[i] % 2 != 0) {
            if (oddsFound== numberOddsSought) {
                return true;
            }
            oddsFound++;
        }
    }

    return false;
}
Alan
We're looking for odd numbers, not even ones.
Jon Skeet
my bad. thanks for the catch.
Alan
You don't initialize oddsFound. And, you're incrementing oddsFound AFTER doing the test? Ummm... your code has issues.
BoltBait
A: 

Thank you for your answers and comments.

I now understand well how to test whether an integer is odd. For example, this method is a neat way of doing this test without using multiplication, modulus, or division operators:

 protected boolean isOdd(int i) {
 return ( (i&1) == 1);

}

With your help, I now realize that the problem is much simpler than I had expected. Here is the rest of my implementation in Java. Comments and criticism are welcome.

protected boolean isOddProduct(int[] arr) {
     int oddCount = 0;
     if (arr.length < 2) 
      throw new IllegalArgumentException();
     for (int i = 0; i <= arr.length-1; i++) {
      if (isOdd(arr[i]))
       oddCount++; 
     }
     return oddCount > 1;
    }

I wonder if there exists any other ways to perform this test without using *, % or / operators? Maybe I'll ask this question in a new thread.

the last if statement is unnecessary, just return oddCount > 1; (this is a big pet peeve of mine.
mmattax
Also, you could write the isOdd function simply as "return (i " - no need for the return true/false statements as you already have a Boolean value from the test.
Greg Beech
Thank you mmattax and Greg for your comments--I went back and fixed this .