Computer Applications
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.
Java
Java Conditional Stmts
80 Likes
Answer
import java.util.Scanner;
public class KboatMenu
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Buzz Number");
System.out.println("Type 2 for Even/Odd");
System.out.println("Type 3 for Positive/Negative");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
System.out.print("Enter number: ");
int n = in.nextInt();
switch (ch) {
case 1:
if (n % 7 == 0 || n % 10 == 7)
System.out.println(n + " is a Buzz Number");
else
System.out.println(n + " is not a Buzz Number");
break;
case 2:
if (n % 2 == 0)
System.out.println(n + " is a Even Number");
else
System.out.println(n + " is an Odd Number");
break;
case 3:
if (n >= 0)
System.out.println(n + " is a Positive Number");
else
System.out.println(n + " is a Negative Number");
break;
default:
System.out.println("Incorrect choice");
}
}
}
Output



Answered By
16 Likes
Related Questions
Which of the following is true about the
default
label in aswitch
statement?Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters Unicode A 65 B 66 . . . . . . Z 90 (b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5A student executes the following program segment and gets an error. Identify the statement which has an error, correct the same to get the output as WIN.
boolean x = true; switch(x) { case 1: System.out.println("WIN"); break; case 2: System.out.println("LOOSE"); }
A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not.
For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.