Programming Examples

Java Program to print first n Buzz Number


Write a Java program which accept the value of n from user and print First N buzz Number.

A Buzz Number is a number that is either divisible by 7 or ends with 7. Here's a Java program that takes an integer n as input and prints the first n Buzz Numbers using a do while loop:

Solution

import java.util.Scanner;

public class BuzzNumber {
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of n: ");
        int n = scanner.nextInt();
        int count = 0; // To count the number of Buzz Numbers found
        int number = 1; // To check each number starting from 1
        System.out.println("The first " + n + " Buzz Numbers are:");
        // Use a do-while loop to find and print the first n Buzz Numbers
        do {
            if (number % 7 == 0 || number % 10 == 7) {
                System.out.print(number + " ");
                count++;
            }
            number++;
        } while (count < n);
    }
}
Output

Enter the value of n: 10

The first 10 Buzz Numbers are:

7 14 17 21 27 28 35 37 42 47 

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz