Program 1.
Write a menu driven program in Java to accept a number and perform the
following operations depending on the user's choice:
Entered number is a Buzz number or not.
Entered number is even or odd.
Entered number is positive or negative.
Note: A Buzz number is a number which is either divisible by 7 or has 7 in its unit's place.
Answer
import [Link];
public class KboatMenu
{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Type 1 for Buzz Number");
[Link]("Type 2 for Even/Odd");
[Link]("Type 3 for Positive/Negative");
[Link]("Enter your choice: ");
int ch = [Link]();
[Link]("Enter number: ");
int n = [Link]();
switch (ch) {
case 1:
if (n % 7 == 0 || n % 10 == 7)
[Link](n + " is a Buzz Number");
else
[Link](n + " is not a Buzz Number");
break;
case 2:
if (n % 2 == 0)
[Link](n + " is a Even Number");
else
[Link](n + " is an Odd Number");
break;
case 3:
if (n >= 0)
[Link](n + " is a Positive Number");
else
[Link](n + " is a Negative Number");
break;
default:
[Link]("Incorrect choice");
}
}
}
Variable Description Table
Variable Type Description
In Scanner Used to take user input from the keyboard
Ch Int Stores the choice you select (1, 2, or 3)
n int Stores the number entered by the user to check