Find the given number as even or odd in Java

This example will prompt to enter any integer number and as per the formula it will print weather the number is even or odd.

import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Please enter any integer number: ");
        int number = scanner.nextInt();

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


Output:

Please enter any integer number: 7
7 is an odd number

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete