write a menu driven program in java to enter a 4 digit number.Perform the following operations depending upon user's choice.i) check whether the entered number is a tech number or not ii)checks whether the entered number is buzz number or not. iii)exit from the program.
Answers
Question:-
Write a menu driven program in Java to enter a 4 digit number. Perform the following operations depending upon the user's choice.
- Check whether the entered number is a tech number or not.
- Check whether the entered number is a buzz number or not.
- Exit the program.
Code:-
import java.util.*;
class Number
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a four digit number: ");
int n=sc.nextInt();
System.out.println("1. Checks Tech Number.");
System.out.println("2. Checks Buzz Number.");
System.out.println("3. Exit the program. ");
System.out.print("\n Enter the choice: ");
int ch=sc.nextInt();
switch(ch)
{
case 1:
if(isTech(int n))
System.out.println("Number is a Tech Number.");
else
System.out.println("Number is not a Tech Number.");
break;
case 2:
if(isBuzz(int n))
System.out.println("Number is a Buzz Number.");
else
System.out.println("Number is not a Buzz Number.");
break;
case 3:
System.exit(0);
}
} // main()
static boolean isTech(int n)
{
int s=n/100 + n%100;
s*=s;
return (s==n);
}
static boolean isBuzz(int n)
return ((n%7==0) || (n%10==7));
} // end of class