Uncategorized

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

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

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

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

Click to comment

Leave a Reply

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

To Top