- 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 9
Conditional Constructs in Java
Class 9 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Programs - Buzz Number & Automorphic Number (Menu-Driven)
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.
import java.util.Scanner;
public class NumberCheckMenu {
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 (1 or 2): ");
int choice = sc.nextInt();
System.out.print("Enter a number: ");
int num = sc.nextInt();
switch (choice) {
case 1: // Buzz Number
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
int square = num * num;
String numStr = String.valueOf(num);
String squareStr = String.valueOf(square);
if (squareStr.endsWith(numStr)) {
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
Output 1 : (Buzz Number)
SAMPLE INPUT : Enter your choice (1 or 2): 1 Enter a number: 49 SAMPLE OUTPUT : 49 is a Buzz Number.Output 2 : (Buzz Number)
SAMPLE INPUT : Enter your choice (1 or 2): 1 Enter a number: 23 SAMPLE OUTPUT : 23 is NOT a Buzz Number.Output 3 : (Automorphic Number)
SAMPLE INPUT : Enter your choice (1 or 2): 2 Enter a number: 25 SAMPLE OUTPUT : 25 is an Automorphic Number.Output 4 : (Automorphic Number)
SAMPLE INPUT : Enter your choice (1 or 2): 2 Enter a number: 12 SAMPLE OUTPUT : 12 is NOT an Automorphic Number.
Explanation
1. Menu Display
System.out.println("1. Check Buzz Number");
System.out.println("2. Check Automorphic Number");
- Allows the user to choose the operation.
2. Buzz Number Logic
num % 7 == 0 || num % 10 == 7
- Divisible by 7 OR
- Last digit is 7
3. Automorphic Number Logic
- Square the number.
- Convert number and square to strings.
- Check if square ends with the original number.
squareStr.endsWith(numStr)
4. switch Statement
- Executes the selected option.
- Handles invalid menu choice.
