Find Odd or Even Program in Java

Advertisements

Prev Tutorial Next Tutorial

Java Program to Find Odd or Even number

In below code i will show you how to design Java Program to Find Odd or Even number. In this program we receive input value from keyboard and find modulo 2 (num%2) of number if reminder of number is zero then that number is even other wise odd. Even numbers are those which are divisible by 2, and which numbers are not divisible 2 is called odd numbers.

Java Program to Find Odd or Even

import java.util.Scanner;
class Oddeven 
{
	public static void main(String[] args) 
	{
    int no;
	Scanner s=new Scanner(System.in);
    System.out.println("Enter any number :");
	no=s.nextInt();
    if(no%2==0)
	{
	System.out.println("Even number");
	}
	else
	{
	System.out.println("Odd number");
	}
	}
}

Output

Enter any number : 
10
Even number

Syntax to compile and run java program

Syntax

for compile -> c:/javac Oddeven.java
for run -> c:/java Oddeven

Explnation of Code

  • Scanner s=new Scanner(System.in): are used for receive input from keyboard.
  • nextInt(): method are used for get integer type value from keyboard.
  • System.out.println("....."): are used for display message on screen or console.

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements