Buzz Number Program in Java for ICSE Class 9 & 10

⚡ Direct Answer & Key Takeaway

In CISCE ICSE Computer Applications, a Buzz number is any integer that is either divisible by 7 or ends with the digit 7. Using Java arithmetic operators, divisibility by 7 is tested with n % 7 == 0, while the last digit is extracted with n % 10 == 7. Combining both tests using the logical OR operator (||) correctly identifies numbers like 49, 27, and 77 while rejecting numbers like 71.

1. Modulus (%) Operator Logic Behind Both Buzz Conditions

Unlike multi-digit extraction programs that require a while loop, a Buzz number check executes in constant time using two remainder expressions. First, n % 7 == 0 verifies whether 7 divides n with no remainder, catching multiples such as 14, 21, and 63. Second, n % 10 == 7 isolates the units digit, catching numbers like 17, 37, and 107 that are not multiples of 7. Because Java short-circuits the || operator, if n % 7 == 0 evaluates to true, the runtime skips checking n % 10 == 7 and branches straight into the Buzz output.

  • Use == for comparison, never = (assignment), inside if (n % 7 == 0 || n % 10 == 7).
  • Wrap negative inputs in Math.abs(n) so -27 % 10 becomes 7 rather than -7 in Java.
  • Avoid converting the integer to a String just to call endsWith("7") in standard ICSE exams.

2. Single-Number Check vs. Menu-Driven Range Printing

ICSE question papers ask for Buzz numbers in two formats: checking one user-entered number, or pairing Buzz checking with another test inside a switch-case menu. In a switch-case question (commonly paired with Automorphic or GCD tasks), place the Buzz condition inside case 1 and end it with break so execution does not fall through into case 2. If asked to print all Buzz numbers within a range from start to end, wrap the exact same if condition inside a for loop and separate printed values cleanly on screen.

  • Include a default branch in menu-driven switch programs for invalid choice numbers.
  • Place break at the end of every switch case to prevent accidental fall-through.
  • Remember that 70 is a Buzz number (70 % 7 == 0) even though it ends in 0.

3. Section A Output Traps: Logical OR vs. AND and Operator Precedence

Section A short-answer questions often test whether you confuse logical OR (||) with logical AND (&&) or bitwise OR (|). Writing n % 7 == 0 && n % 10 == 7 restricts matches strictly to numbers like 7 and 77 that satisfy both rules simultaneously, wrongly rejecting 14 and 27. Also remember that arithmetic % has higher precedence than relational ==, which in turn binds tighter than logical ||. Therefore, n % 7 == 0 || n % 10 == 7 evaluates accurately even without extra inner parentheses.

  • Test 14 (divisible only), 27 (ends in 7 only), 77 (both), and 71 (neither, starts with 7).
  • Watch out for 71 or 73: starting with 7 does NOT make a number a Buzz number.
  • In ternary form, write String res = (n % 7 == 0 || n % 10 == 7) ? "Buzz" : "Not Buzz";

4. BuzzNumber.java (Single Check + Range Listing)

import java.util.*;

public class BuzzNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter an integer: ");
        int n = sc.nextInt();

        int absVal = Math.abs(n);
        boolean divBy7 = (absVal % 7 == 0);
        boolean endsWith7 = (absVal % 10 == 7);

        if (divBy7 || endsWith7) {
            System.out.println(n + " is a Buzz Number");
        } else {
            System.out.println(n + " is NOT a Buzz Number");
        }

        System.out.print("Enter upper limit to list Buzz numbers from 1: ");
        int limit = sc.nextInt();
        System.out.print("Buzz numbers up to " + limit + ": ");
        for (int i = 1; i <= limit; i++) {
            if (i % 7 == 0 || i % 10 == 7) {
                System.out.print(i + " ");
            }
        }
        System.out.println();
        sc.close();
    }
}

Verified Console / Dry-Run Output:

Enter an integer: 27
27 is a Buzz Number
Enter upper limit to list Buzz numbers from 1: 30
Buzz numbers up to 30: 7 14 17 21 27 28

5. CISCE Variable Description Table (VDT) & Dry Run

VariableData TypeExam Purpose & Sample Value
nintUser-entered integer tested for Buzz property (e.g., 27)
absValintMagnitude Math.abs(n) ensuring % 10 handles negative inputs (27)
divBy7booleanTrue when absVal % 7 == 0 (false for 27, true for 49)
endsWith7booleanTrue when absVal % 10 == 7 (true for 27, false for 71)
limitintUpper bound for listing Buzz numbers starting from 1 (e.g., 30)
iintLoop counter iterating 1 through limit (prints 7, 14, 17, 21, 27, 28)
🎯 1-on-1 Live Mentorship & Free Study Kit

Ace ICSE Operators & Switch Menus Live

Sharpen Section A operator precedence, switch-case menus, and modulus tricks in a personalized 1-on-1 ICSE Java class.

💬 WhatsApp Now
🔒 Instant WhatsApp notes + free 60-min 1-on-1 trial session
Confirmed! Our Senior Mentor is sending your study kit & free 1-on-1 demo link on WhatsApp now.

6. Common Mistakes & Top Scorer Tips

  • Avoid Mistake: Using logical AND (&&) instead of logical OR (||), which wrongly rejects single-condition Buzz numbers like 14 and 27.
  • Avoid Mistake: Checking whether any digit equals 7 using a while loop, which misclassifies 71 or 72 as Buzz numbers.
  • Avoid Mistake: Using n / 10 == 7 instead of n % 10 == 7, which checks the leading digit of a two-digit number rather than its units digit.
  • Examiner / Mentor Tip: In ICSE menu-driven switch questions, test your Buzz case with 49, 27, and 71 before submitting your practical file.
  • Examiner / Mentor Tip: Remember Java's % operator preserves the sign of the dividend (-27 % 10 == -7), so Math.abs(n) earns extra accuracy points.
  • Examiner / Mentor Tip: If asked to rewrite the Buzz condition in one line for Section A, use the ternary ?: operator with ||.

7. Interactive Concept Check Quiz

Question: Which of the following integers is NOT a Buzz number in Java?

8. Frequently Asked Questions

Is 0 considered a Buzz number in ICSE Java?
Mathematically 0 % 7 equals 0, so a pure divisibility test evaluates to true for 0. However, most ICSE Class 9 and 10 school worksheets treat Buzz numbers as positive integers starting from 1. If your question asks for natural numbers only, add an if (n <= 0) guard before testing the two Buzz conditions.
Why is 71 not a Buzz number even though it contains the digit 7?
The Buzz definition checks only two properties: divisibility by 7 and whether the final (units) digit is 7. For 71, 71 % 7 gives a remainder of 1 and 71 % 10 gives 1, not 7. Having a 7 in the tens or hundreds place does not qualify a number as Buzz.
Can we write the Buzz number check using the ternary operator in BlueJ?
Yes, CISCE Section A questions frequently ask students to rewrite Buzz logic using the ternary operator. You can write String msg = (n % 7 == 0 || n % 10 == 7) ? "Buzz Number" : "Not a Buzz Number"; which evaluates identically to the standard if-else block in one concise line.

Explore Related Lessons & Free Interactive Tools

Free 1-on-1 Session

Book a Free Demo Class