Buzz Number Program in Java2 min read

In this tutorial, we will start with what is Buzz Number and Write a Java Program to check whether the number is Buzz Number or not.

Buzz Number

A Buzz number is one of the special numbers that end with 7 or is divisible by 7.

For example: 7, 17, 27, 37, etc are buzz numbers because they end with 7, and the numbers 7, 14, 21, 28, etc are also buzzed numbers because they are divisible by 7.


Program Approach to check the Buzz Number.

1. First take a number that needs to be checked for Buzz.

2. We then apply a condition to check the two conditions needed to check for the Buzz number.

  • We check if the last digit is 7 or not with % operator (number % 10 == 7), which gives us the remainder.
  • Then, we check the divisibility of a number by 7 with / operator (num / 7 == 0).

3. Both of these conditions are checked together in with || operator, in which if either one is true then || (or) operator returns a true value. Indicating the number is Buzz number.

4. Else the number is not a Buzz number.


Java Program to check whether the number is Buzz Number or not

Output:

//Run: 1
Enter a number to check for Buzz: 17
17 is a Buzz number.

//Run: 2
Enter a number to check for Buzz: 32
32 is a not Buzz number.


Java program to display all the Buzz number in a given Range

This is another example where we will print all the Buzz numbers in a given range in Java.

Output:

Enter the lower range: 0
Enter the Upper range: 50
List of all the buzz number between 0 and 50
7
14
17
21
27
28
35
37
42
47
49

You may create a separate boolean function to check for the Buzz number and return the number to the main function. Call the boolean function inside the for loop in the main function.


MORE

Java Program to find the sum of the Largest Forward Diagonal

in this tutorial, we will write a java program to find the sum of the Largest Forward Diagonal in an Arraylist (matrix). Java Program to …

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …