- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Iterative Constructs in Java
Chapter 9
Iterative Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Menu Driven Program - Buzz Number and GCD Checker
27. Write a menu driven program to accept a number from the user and check whether it is a BUZZ number or to accept any two numbers and to print the GCD of them.
(1). A BUZZ number is the number which either ends with 7 or is divisible by 7.
(2). GCD (Greatest Common Divisor) of two integers is calculated by continued division method. Divide the larger number by the smaller; the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.
Program Title: Buzz Number and GCD Checker
import java.util.Scanner;
public class BuzzGCDMenu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("MENU");
System.out.println("1. Check Buzz Number");
System.out.println("2. Find GCD of Two Numbers");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
// Check Buzz number
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num % 10 == 7 || num % 7 == 0) {
System.out.println(num + " is a Buzz Number.");
} else {
System.out.println(num + " is NOT a Buzz Number.");
}
break;
case 2:
// Compute GCD
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
int x = a, y = b;
while (y != 0) {
int remainder = x % y;
x = y;
y = remainder;
}
System.out.println("GCD of " + a + " and " + b + " is: " + x);
break;
default:
System.out.println("Invalid choice! Please select 1 or 2.");
}
sc.close();
}
}
Output
Sample Output 1 (Buzz Number) MENU 1. Check Buzz Number 2. Find GCD of Two Numbers Enter your choice: 1 Enter a number: 35 35 is a Buzz Number. Sample Output 2 (GCD) MENU 1. Check Buzz Number 2. Find GCD of Two Numbers Enter your choice: 2 Enter first number: 48 Enter second number: 180 GCD of 48 and 180 is: 12
📝 Explanation
1. Buzz Number:
- A number is a Buzz number if it ends with 7 (num % 10 == 7)
OR is divisible by 7 (num % 7 == 0).
2. GCD (Euclidean Algorithm):
- Continuously divide the larger number by the smaller number.
- Replace the larger number with the smaller, and the smaller with the remainder.
- Repeat until remainder = 0.
- The divisor at that point is the GCD.
3. Switch-case is used for menu selection.
