please tell proper answer by either doing in copy or here.
6 Write a menu driven program in java using switch case. Main Menu
1. Prime number (A number is a divisible by 1 and itself)
2. Perfect number.
Answers
Answer:
import java.util.Scanner;
import java.util.Scanner;
public class PrimeExample{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter a number : ");
int n = s.nextInt();
if (isPrime(n)) {
System.out.println(n + " is a prime number");
} else {
System.out.println(n + " is not a prime number");
}
}
public static boolean isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i < Math.sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
Explanation:
prime number