beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Java Program to check Even or Odd number

By Chaitanya Singh | Filed Under: Java Examples

import java.util.Scanner;

class CheckEvenOdd
{
  public static void main(String args[])
  {
    int num;
    System.out.println("Enter an Integer number:");

    //The input provided by user is stored in num
    Scanner input = new Scanner(System.in);
    num = input.nextInt();

    /* If number is divisible by 2 then it's an even number
     * else odd number*/
    if ( num % 2 == 0 )
        System.out.println("Entered number is even");
     else
        System.out.println("Entered number is odd");
  }
}

Output 1:

Enter an Integer number:
78
Entered number is even

Output 2:

Enter an Integer number:
77
Entered number is odd

Enjoyed this post? Try these related posts

  1. Java Program to find area of Geometric figures using method Overloading
  2. Java Program to Calculate Simple Interest
  3. Java program for binary to decimal conversion
  4. Java Program to Perform Arithmetic operation using Method Overloading
  5. Java program to display prime numbers from 1 to 100 and 1 to n
  6. Java Program to Check if given Number is Perfect Square

Comments

  1. kaushik says

    November 14, 2015 at 3:25 AM

    there are errors in the program its saying that FILE DOES NOT CONTAIN CLASS SCANNER :\

    Reply
  2. arul says

    December 14, 2015 at 7:11 AM

    if i run any programs like usergetinputs it shows the following error
    ” class java.util.Scanner not found in import.”
    please help me to correct this error thank you.

    Reply
    • Sultan says

      April 29, 2016 at 2:02 PM

      import package java.util.Scanner;
      Then it will not show any error..!

      Reply
  3. Rukhsaar says

    March 16, 2017 at 1:07 AM

    I tried this and there were no errors whatsoever .

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Programs

  • C Programs
  • Java Programs

Java Examples

  • Check Odd-even
  • Linear Search
  • Binary Search
  • Floyd's Triangle
  • Reverse number
  • Random Number
  • first n prime numbers
  • Disp prime Numbers
  • Check Prime number
  • Palindrome String
  • Find factorial
  • Sum of elements of Array
  • Area of rectangle
  • Area of Square
  • Area of Triangle
  • Circle

Tutorials

  • Java Tutorial
  • OOPs Concepts
  • Java String
  • Exception handling
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap