write a java program that checks if the numbers between 10 to 15 are prime or not and displays them.
Answers
Answered by
4
Question:-
Write a java program that checks if the numbers between 10 to 15 are prime or not and displays them.
Code:-
class x
{
static boolean isPrime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
return (c==2);
}
static void main()
{
for(int i=10;i<=15;i++)
{
if(isPrime(i))
System.out.print(i+" ");
}
}
}
Similar questions