First type:
public class prime number 1 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
1-100 within the and of prime numbers
int sum=0;
for (int i=1;i<=100;i++)
{
Boolean b=true;
if (i!=1)
{
for (int j=2;j<i;j++)
{
if (i%j==0)
{
B=false;
Break
}
}
if (b)
{
Sum+=i;
System.out.println (i);
}
}
}
System.out.println ("The and of the prime numbers for:" +sum);
}
}
The second type:
public class prime number 2 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
int sum=0;
Int J;
for (int i = 2; I <= i++)//1 is not a prime, so loop directly from 2
{
j = 2;
while (i% J!= 0) {
j + +; Test whether the number 2 to I is divisible by I, and if not, add
}
if (j = = i)//when there is an divisible number, judge whether it is itself
{
Sum+=i;
System.out.println (i); If it is, print out the numbers.
}
}
System.out.println ("The and of the prime numbers for:" +sum);
}
}