Q:

Java program to check whether input number is EVEN or ODD

belongs to collection: Java Basic Programs

0

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.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to swap two numbers with and without ... >>
<< Java program to find Square, Cube and Square Root ...