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