Kodekraftt
/Blog
/Check Whether A Number Is A Buzz Number In Java Without Using Modulo Operator
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

Check Whether a Number Is a Buzz Number in Java Without Using Modulo Operator

Learn how to check whether a number is a Buzz Number in Java without using the modulo (%) operator, using simple arithmetic logic and clean programming concepts.

Check Whether a Number Is a Buzz Number in Java Without Using Modulo Operator

A Buzz Number is a number that is either:

  • Divisible by 7, or
  • Ends with the digit 7

In this program, we will check a Buzz Number without using the modulo (%) operator, which makes the logic more interesting and interview-oriented.

Examples of Buzz Numbers

  • 7 → Buzz Number (divisible by 7 and ends with 7)
  • 14 → Buzz Number (divisible by 7)
  • 27 → Buzz Number (ends with 7)
  • 25 → Not a Buzz Number

How Can We Avoid the Modulo Operator?

Instead of using number % 7, we can:

  • Use integer division to remove multiples of 7
  • Check the last digit using subtraction and division

Logic Explanation

  1. Store the original number.
  2. Check if the number ends with 7 using arithmetic.
  3. Check divisibility by 7 by subtracting multiples of 7.
  4. If either condition is true, it is a Buzz Number.

Java Program (Without Using % Operator)


import java.util.Scanner;

public class BuzzNumberWithoutModulo {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        int original = num;

        // Check if number ends with 7
        int lastDigit = num - (num / 10) * 10;

        boolean endsWithSeven = (lastDigit == 7);

        // Check divisibility by 7 without modulo
        int temp = num;
        while (temp > 0) {
            temp = temp - 7;
        }

        boolean divisibleBySeven = (temp == 0);

        if (endsWithSeven || divisibleBySeven) {
            System.out.println(original + " is a Buzz Number");
        } else {
            System.out.println(original + " is NOT a Buzz Number");
        }
    }
}

Sample Output


Enter a number: 27
27 is a Buzz Number

Enter a number: 25
25 is NOT a Buzz Number

Important Notes

  • No modulo (%) operator is used.
  • Uses basic arithmetic operations only.
  • Works for positive integers.

Practice Challenges

  1. Check Buzz Number using only addition and subtraction.
  2. Modify the program to handle negative numbers.
  3. Print all Buzz Numbers between 1 and 100 without using %.

This problem strengthens mathematical thinking and shows how operators like modulo can be replaced using pure logic.

You might also like

Check if Two Strings Are Rotations of Each Other in Java — Definition, Examples and Program

Learn how to check whether two strings are rotations of each other in Java using logical string comparison without using complex libraries.

Find the Shortest Word in a Sentence in Java — Definition, Examples and Program

Learn how to find the shortest word in a sentence in Java using a simple character-by-character approach without using split() or advanced string methods.

Abundant Number in Java — Definition, Examples and Program

Learn what an abundant number is in Java with definition, examples, and a clean program to check whether a number is abundant or not.

Concatenate Two Strings in Java Without Using + Operator — Examples and Program

Learn how to concatenate two strings in Java without using the + operator. This blog explains the logic with examples, a Java program, and practice challenges.

Check if a String is Empty or Null in Java — Definition, Examples and Program

Learn how to check whether a string is null or empty in Java. This blog explains the difference, common mistakes, examples, and a safe Java program with practice challenges.

Convert String to Uppercase in Java Without Using String Library

Learn how to convert a string to uppercase in Java without using built-in String methods. This blog explains the ASCII-based logic with examples, a Java program, and practice challenges.