Saturday 30 January 2016

Write a Program in Java to check if Number is Buzz Number or not.

Buzz Number: A number is said to be Buzz Number if it ends with 7 or is divisible by 7.

Example: 1007 is a Buzz Number as it end with 7. 343 is also a Buzz Number as it is divisible by 7 and 77777 is also a Buzz Number as it ends with 7 and also it is divisible by 7.

Program:
import java.util.*;
class BUZZ
{
Scanner sc=new Scanner(System.in);
int n;
public void function( )
{
System.out.println("Enter the number:");
n=sc.nextInt();
if ( n % 10 == 7  ||  a % 7 == 0 )
System.out.println("Entered number is a Buzz number.");
else
System.out.println("Entered number is not a Buzz number.");
}
public static void main(String args[ ])
{
 BUZZ ob = new BUZZ();
 ob.function( );
}
}

Sample Output:

Enter the number:
37
Entered number is a Buzz number.

Enter the number:
21
Entered number is a Buzz number.

Enter the number:
123
Entered number is not a Buzz number.

17 comments: