- import java.util.Scanner;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- class EvenOddPrime
- {
- public static void main(String args[]) throws Exception
- {
- BufferedReader in = new BufferedReader(new InputStreamReader(System. in ));
- System.out.println("1-Check even or odd number");
- System.out.println("2-Check prime number or not");
- System.out.println();
- System.out.print("Select any option: ");
- int select = Integer.parseInt( in .readLine());
- switch (select)
- {
- case 1:
- int num;
- System.out.print("Enter an Integer number: ");
-
- Scanner input = new Scanner(System. in );
- num = input.nextInt();
-
-
- if (num % 2 == 0) System.out.println("Entered number is even");
- else System.out.println("Entered number is odd");
- break;
- case 2:
- int temp;
- boolean isPrime = true;
- Scanner scan = new Scanner(System. in );
- System.out.print("Enter an integer number: ");
-
- int numb = scan.nextInt();
- for (int i = 2; i <= numb / 2; i++)
- {
- temp = numb % i;
- if (temp == 0)
- {
- isPrime = false;
- break;
- }
- }
-
- if (isPrime) System.out.println(numb + " is a Prime Number");
- else System.out.println(numb + " is not a Prime Number");
- }
- }
- }
Thank you, keep learning and sharing