Thursday, April 22, 2010

Even or Odd program using java

This program will determine if the number inputted by the user is even or odd.

we use here a modulo operator to get the even or odd numbers.

Modulo - this operator use in programming to get the remainder.

sample program:

import java.util.Scanner;

public class EvenOdd
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);

int num;

System.out.print("Enter a number:");
num=input.nextInt();

if(num%2==0)
{
System.out.print("Even number");
}
else if(num%2==1)
{
System.out.print("Odd Numbers");
}
}
}

No comments:

Post a Comment