# Write a Java Program to Check Buzz Number

In the previous article, we have discussed Java Program to Check Automorphic Number

In this article we are going to understand what Buzz number is and how we can check whether a number is Buzz or not in Java with examples.

## Java Program to Check Buzz Number

Buzz numbers are numbers which are divisible by 7 or contain 7 if it ends with 7.

Example:

49 -> Buzz number
67 -> Buzz number
99 -> not a Buzz number

In the above examples the number 49 is divisible by 7 and number 67 has 7 at its end. Both of them are either divisible by 7 or have 7 at its end hence they are Buzz number. However, 99 is not divisible by 7 and neither does it contain 7 at its end. Hence 9 is not a Buzz number.

Let’s see different ways to check Buzz number.

Approach:

1. We ask the user to enter a number which we store in an integer variable num.
2. Then the number is divided by 10 to see if it leaves 7 as a remainder, if not its divisibility by 7 is checked.
3. If the number passed either of the condition it is a Buzz number else not.

### Method-1:Java Program to Check Buzz Number By Using Static Value

import java.util.Scanner;
public class BuzzNumber
{
public static void main(String args[])
{
//A number is declared
int num = 49;

//Checks whether the number is divisble by 7 or has 7 at its end
if (num % 10 == 7 || num % 7 == 0)
{
System.out.println(num+" is a Buzz number");
}
else
{
System.out.println(num+" is not a Buzz number");
}
}
}

Output:

49 is a Buzz number

### Method-2: Java Program to Check Buzz Number By Using User Input Value

import java.util.Scanner;
public class BuzzNumber
{
public static void main(String args[])
{
//Taking the number as input from the user using scanner class
Scanner scan = new Scanner(System.in);
System.out.print("Enter a number : ");
int num = scan.nextInt();

//Checks whether the number is divisble by 7 or has 7 at its end
if (num % 10 == 7 || num % 7 == 0)
{
System.out.println(num+" is a Buzz number");
}
else
{
System.out.println(num+" is not a Buzz number");
}
}
}

Output:

Enter a number : 97
97 is a Buzz number

### By Using C Language:

#include<stdio.h>

int main()
{
//an integer variable declared
//to store the number
int number;

printf("Enter a number : ");
//taking a number input
scanf("%d",&number);

//checking buzz number or not
if(number%10==7||number%7==0)
printf("%d is a Buzz number",number);
else
printf("%d is not a Buzz number",number);
return 0;
}

Output:

Enter a number : 7
7 is a Buzz number

Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.

Related Java Programs: