Write a java program to find the sum of all prime numbers between 1 and 100.
Answers
Answered by
6
class prime1To100
{
public static void main()
{
int sum=0,i,k,j;
for(i=1;i<100;i++)
{
k=0;
for(j=2;j<i;j++)
{
if(i%j==0)
{
k=1;
break;
}
}
if(k==0)
{
sum=sum+i;
}
}
System.out.println("Sum = "+sum);
}
}
{
public static void main()
{
int sum=0,i,k,j;
for(i=1;i<100;i++)
{
k=0;
for(j=2;j<i;j++)
{
if(i%j==0)
{
k=1;
break;
}
}
if(k==0)
{
sum=sum+i;
}
}
System.out.println("Sum = "+sum);
}
}
Arijit98:
can you explain how this program works
Similar questions