- 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
Conditional Constructs in Java
Chapter 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Java Menu-Driven Program to check whether a number is a Buzz number or an Automorphic number
31. Write a menu driven program to accept a number from the user and check whether it is a Buzz number or an Automorphic number.
i. Automorphic number is a number, whose square's last digit(s) are equal to that number. For example, 25 is an automorphic number, as its square is 625 and 25 is present as the last two digits.
ii. Buzz number is a number, that ends with 7 or is divisible by 7.
🧫 Definitions Recap
- Buzz Number
A number that ends with 7 OR is divisible by 7
Examples: 7, 14, 27, 77 - Automorphic Number
A number whose square ends with the number itself
Example:
25² = 625 → Automorphic
import java.util.Scanner;
public class BuzzAutomorphic {
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. Check Automorphic Number");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
System.out.print("Enter a number: ");
int num = sc.nextInt();
switch (choice) {
case 1:
// Buzz Number Check
if (num % 7 == 0 || num % 10 == 7)
System.out.println(num + " is a Buzz Number");
else
System.out.println(num + " is NOT a Buzz Number");
break;
case 2:
// Automorphic Number Check
int square = num * num;
int temp = num;
boolean isAutomorphic = true;
while (temp > 0) {
if (temp % 10 != square % 10) {
isAutomorphic = false;
break;
}
temp /= 10;
square /= 10;
}
if (isAutomorphic)
System.out.println(num + " is an Automorphic Number");
else
System.out.println(num + " is NOT an Automorphic Number");
break;
default:
System.out.println("Invalid choice");
}
sc.close();
}
}
Output
Sample Run 1 MENU 1. Check Buzz Number 2. Check Automorphic Number Enter your choice: 1 Enter a number: 27 27 is a Buzz Number Sample Run 2 MENU 1. Check Buzz Number 2. Check Automorphic Number Enter your choice: 2 Enter a number: 25 25 is an Automorphic Number
📝 Explanation
- Program uses switch-case for menu selection
- Buzz number logic:
- num % 7 == 0 OR num % 10 == 7
- Automorphic logic:
- Compare last digits of number and its square using a loop
- Displays an error message for incorrect choice
