Computer Science, asked by yashrobert176, 14 days ago

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 ​

Answers

Answered by amansarrafas24payxgs
1

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...

Similar questions