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
83 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
Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'.
Sample Input: 56, -15, 12
Sample Output:
The greatest number is 56
Entered numbers are mixed numbers.An air-conditioned bus charges fare from the passengers based on the distance travelled as per the tariff given below:
Distance Travelled Fare Up to 10 km Fixed charge ₹80 11 km to 20 km ₹6/km 21 km to 30 km ₹5/km 31 km and above ₹4/km Design a program to input distance travelled by the passenger. Calculate and display the fare to be paid.
Write a Java program to print name, purchase amount and final payable amount after discount as per given table:
Purchase Amount Discount upto ₹10000/- 15% ₹10000 to ₹ 20000/- 20% Above ₹20000/- 30% 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.