How to analyze evenness/oddness of numbers in Java

Posted by appreciation on Stack Overflow See other posts from Stack Overflow or by appreciation
Published on 2009-10-30T23:38:12Z Indexed on 2010/05/09 21:08 UTC
Read the original article Hit count: 180

Filed under:
|

I have to write a program which reads in 3 numbers (using input boxes), and depending on their values it should write one of these messages:

  • All 3 numbers are odd OR
  • All 3 numbers are even OR
  • 2 numbers are odd and 1 is even OR
  • 1 number is odd and 2 are even

This is what I have so far:

import javax.swing.JOptionPane;
class program3

{
    public static void main(String[] args)

    {

        String num1 = JOptionPane.showInputDialog("Enter first number.");
        String num2 = JOptionPane.showInputDialog("Enter second number.");
        String num3 = JOptionPane.showInputDialog("Enter third number.");

        boolean newnum1 = Integer.parseInt(num1);
        boolean newnum2 = Integer.parseInt(num2);
        boolean newnum3 = Integer.parseInt(num3);
    }

}

This is where I am stuck. I am not sure how to use the MOD to display the messages. I think I have to also use an IF Statement too...But I'm not too sure.

Please help! :D

© Stack Overflow or respective owner

Related posts about modulus

Related posts about java