write a Java program to find whether a given number is odd even or prime number
Answers
This program is used to find odd and even numbers:
import java.util.Scanner;
public class Odd_Even
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number you want to check:");
n = s.nextInt();
if(n % 2 == 0)
{
System.out.println("The given number "+n+" is Even ");
}
else
{
System.out.println("The given number "+n+" is Odd ");
}
}
}
The second program is to find whether the number is prime or not
public class PrimeNumbers {
public void prime(int n) {
boolean isPrime = true;
for (int i = 2; i < n; i++) {
if (n % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println(n + " is a prime number");
} else {
System.out.println(n + " is not a prime number");
}
}