Java Program to Check Buzz Number

Welcome to the world of computer programming! In this article, we will discuss how to write a program in Java to accept a number and Check Whether a Number is Buzz Number Or Not. We will look at the different methods and techniques that can be used to accomplish this task.

Today we are going to learn about something fascinating. A buzz number is a number that is either divisible by 7 or has the digit 7 in it. I can’t wait to learn about these interesting numbers.

A buzz number is a number that is either divisible by 7 or has the digit 7 in it.

import java.util.*;

This line imports the entire java.util package which contains utility classes like Scanner, ArrayList, etc.

public class BuzzNumber 

This line starts the declaration of the class BuzzNumber.

public static void main(String[] args) 

line defines the main method, which is the entry point of the program.

Scanner in = new Scanner(System.in);

line creates an object of the Scanner class, which is used to read user input from the console.

int n;

This line declares an integer variable n.

System.out.print("Enter a number: ");

Its prints the message “Enter a number: ” to the console.

int n = in.nextInt();

This line reads an integer from the user input and assigns it to the variable n.

if(n % 7 == 0 || n % 10 == 7)
{
    System.out.println(n + " is a buzz number.");
}
else
{
    System.out.println(n + " is not a buzz number.");
}

This block of code checks whether the input number is a buzz number or not. A buzz number is a number that is either divisible by 7 or has the digit 7 in it. If the condition is true, the program prints a message saying that a number is a buzz number. If the condition is false, the program prints a message saying that the number is not a buzz number.

Overall, this program takes an integer input from the user and checks whether it is a buzz number or not, and outputs the result to the console.

Buzz Number Program:-

import java.util.*;

public class BuzzNumber 
{
    public static void main(String[] args) 
    {
        Scanner in = new Scanner(System.in);
        int n;
        System.out.print("Enter a number: ");
        int n = in.nextInt();
        
        if(n % 7 == 0 || n % 10 == 7)
        {
            System.out.println(n + " is a buzz number.");
        }
        else
        {
            System.out.println(n + " is not a buzz number.");
        }
    }
}

Output:

Enter a number: 17
17 is a buzz number.

Conclusion

In conclusion, this Java program has demonstrated a useful approach to determining whether a given number is even or odd. By making use of the modulo operator, the program was able to determine the remainder of the number when divided by two and then used an if-else statement to determine to Check Whether the Number is Buzz number Or Not. As a result, this program provides an effective and efficient means of checking whether a number is Buzz Or Not.

Share your love