Java program to print N prime numbers and find sum and average


Program

public class PrimeNumberUptoN 
{

public static void main(String[] args)
{
int num =0, i =0;
System.out.println("Prime numbers from 1 to 100 are :");
for (i = 1; i <= 100; i++)
{
int counter=0;
  for(num =i; num>=1; num--)
        {
    if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
System.out.print(i+" ");
}
}
}
}
Output
Prime numbers from 1 to 100 are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97


Related Post

Comments


©candidjava.com