Java Programs
Write a program to find the sum of all the prime numbers between 100 to 200
class prime
{
public static void main(String args[])
{
int sum=0,i,j,prime;
boolean flag=false;
for(i=100;i<=200;i++)
{
flag=false;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=true;
}
}
if(flag==false)
{
System.out.println("Prime ="+i);
sum+=i;
}
}
System.out.println("Sum of prime numbers between 100 and 200 is= "+sum);
}
}
Write a program to find the sum of all the prime numbers between 100 to 200
class prime
{
public static void main(String args[])
{
int sum=0,i,j,prime;
boolean flag=false;
for(i=100;i<=200;i++)
{
flag=false;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=true;
}
}
if(flag==false)
{
System.out.println("Prime ="+i);
sum+=i;
}
}
System.out.println("Sum of prime numbers between 100 and 200 is= "+sum);
}
}