write a program to print prime numbers form 1 to 10 using java.... if u give me correct answer u will be marked as brainliest Irrelevant answers will be reported.......
Answers
Answered by
2
Question:-
Write a program in java to print prime numbers from 2-10 in Java.
Program:-
class Prime
{
public static void main(String args[])
{
for(int i=2;i<=10;i++)
{
if(isPrime(i))
System.out.print(i+" ");
}
}
static boolean isPrime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
return (c==2);
}
}
Similar questions