Uncategorized

Write a Java Program to define a function which accept a number and check it is a even number or not

Write a Java Program to define a function which accept a number and check it is a even number or not.

import java.io.*;
import java.util.*;

class EvenOdd
{
	void check( int n )
	{
		if( n% 2 == 0)
		  System.out.println(" Number is even.");
		else
			System.out.println(" Number is odd.");
	}
  public static void main(String args[ ])
  {
  	Scanner sc = new Scanner(System.in);
  	int n;
  	System.out.println("Enter n =");
  	n = sc.nextInt();
  	EvenOdd ob = new EvenOdd( );
  	ob.check( n );
  }
}

Click to comment

Leave a Reply

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

To Top