Sunday, February 24, 2019

Java Example to check if Number is Odd or Even

Java Example to check if the entered number is Odd or Even. This example is for the beginners who just started learning programming.

import java.util.Scanner;

public class OddOrEven {

    public static void main(String[] args) {

        Scanner reader = new Scanner(System.in);

        System.out.print("Enter the number: ");
        int num = reader.nextInt();

        if(num % 2 == 0)
            System.out.println(num + " is even.");
        else
            System.out.println(num + " is odd.");
    }
}

No comments:

Post a Comment