Using if-else-it statement, write a program
in Java to verify whether the entered number
is odd, even or pime.
Answers
Answered by
1
Answer:
import java.util.*;
public class Num
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int n,c=0;
System.out.println("Enter the number");
n=in.nextInt();
if(n%2==0)
System.out.println(n + " is a even number");
else
System.out.println(n + " is an odd number");
for(int a=1;a<=n;a++)
{
if(n%a==0)
c++;
}
if(c==2)
System.out.println(n + " is a prime number");
else
System.out.println(n + " is not a prime number");
}
}
Output:
Enter the number
19
19 is a odd number
19 is a prime number
Note:Prime numbers are always odd(except 2) so if you write 19 so it will print it as odd number as well as prime number.
Similar questions
Social Sciences,
2 months ago
Hindi,
4 months ago
Math,
4 months ago
Biology,
10 months ago
English,
10 months ago