Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

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