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.
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
Related Questions
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% 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 5Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");