Computer Science, asked by krishviradiya29, 5 months ago

Write a menu driven program to accept a number and check whether the number is: 1) Buzz Number: A Buzz number is such a number which is divisible by 7 or last digit is 7. 2) Even Number: An even number is such a number which is divisible by 2. Use switch case to do the above

Answers

Answered by anindyaadhikari13
5

Question:-

  • Write a menu driven program to accept a number and check whether it is Buzz number or even number using switch case.

Program:-

This is written in Java.

import java.util.*;

class Program

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int a, ch;

System.out.print("Enter a number: ");

a=sc.nextInt();

System.out.println("\n1. Buzz Number.");

System.out.println("2. Even Number.");

System.out.print("Enter your choice: ");

ch=sc.nextInt();

switch(ch)

{

case 1:

if(n%7==0 || n%10==7)

System.out.println("Buzz Number.");

else

System.out.println("Not a Buzz Number.");

break;

case 2:

if(n%2==0)

System.out.println("Even Number. ");

else

System.out.println("Odd Number.");

break;

default:

System.out.println("Invalid Choice.");

}// switch

}// end of main()

}// end of class.

Answered by srimanpari
0

Answer:

ANSWER

import java.util.Scanner;

public class KboatBuzzAutomorphic

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("1. Buzz number");

System.out.println("2. Automorphic number");

System.out.print("Enter your choice: ");

int choice = in.nextInt();

System.out.print("Enter number: ");

int num = in.nextInt();

switch (choice) {

case 1:

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:

int sq = num * num;

int d = 0;

int t = num;

/*

* Count the number of

* digits in num

*/

while(t > 0) {

d++;

t /= 10;

}

/*

* Extract the last d digits

* from square of num

*/

int ld = (int)(sq % Math.pow(10, d));

if (ld == num)

System.out.println(num + " is automorphic");

else

System.out.println(num + " is not automorphic");

break;

default:

System.out.println("Incorrect Choice");

break;

}

}

}

Similar questions