ADVERTISEMENT
ADVERTISEMENT

Java program to check whether input number is EVEN or ODD

Check EVEN or ODD in Java: In this program, we will input an integer number and check whether it is EVEN or ODD.

Given an Integer number and we have to check whether number is EVEN or ODD.

To check number is EVEN or ODD: we will divide number by 2 and check remainder is ZERO or not, if remainder is ZERO, number will be EVEN others number will be ODD.

Consider the program:

import java.util.*;

/* Java Program to check whether entered number is EVEN or ODD */

public class j6 
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int num;

		//inpu
		System.out.print("Enter an integer number: ");
		num=sc.nextInt();
		
		//check EVEN or ODD
		if(num%2 ==0)
		{
			System.out.println(num +" is an EVEN number.");
		}
		else
		{
			System.out.println(num +" is an ODD number.");
		}
	}
}

Output

First Run:
Enter an integer number: 123
123 is an ODD number.

Second Run:
Enter an integer number: 166
166 is an EVEN number.

Java Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.