1a) write a program to input any number. find and print if it is prime number or not. a prime number is number which has two factors only. example 7, 11,13 etc
Please answer this question
Share
1a) write a program to input any number. find and print if it is prime number or not. a prime number is number which has two factors only. example 7, 11,13 etc
Please answer this question
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
import java.util.*;
class Prime
{
public void main()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number: ");
int n = sc.nextInt();
int count = 0;
for(int i = 1;i <= n;i++)
{
if(n%i == 0)
{
count++;
}
}
if(count == 2)
{
System.out.println(n + " is a Prime Number");
}
else
{
System.out.println(n + " is not a Prime Number");
}
}
}
I hope you find it useful... If you have any query do comment, I will try to solve it...