Saturday 14 July 2018

How to Check whether number is even or odd

import java.text.ParseException;

public class TestOddEvenExample {
    public static void main(String args[]) throws ParseException {

        int x = 24;
        oddEvenChecker(x);

        int xx = 3;
        oddEvenChecker(xx);
    }

    static void oddEvenChecker(int x) {
        if (x % 2 == 0)
            System.out.println("You entered an even number." + x);
        else
            System.out.println("You entered an odd number." + x);
    }
}


No comments:

Post a Comment