Computer Science, asked by straiyo, 8 months ago

write a program to print all the prime numbers from 10 to 100 java program​

Answers

Answered by harshit4verma2005
0

Answer:

It will display the prime numbers between 1 and 100.

class PrimeNumbers

{

  public static void main (String[] args)

  {  

      int i =0;

      int num =0;

      //Empty String

      String  primeNumbers = "";

      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)

  {

     //Appended the Prime number to the String

     primeNumbers = primeNumbers + i + " ";

  }  

      }  

      System.out.println("Prime numbers from 1 to 100 are :");

      System.out.println(primeNumbers);

  }

}

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

Program to display prime numbers from 1 to n

It will display all the prime numbers between 1 and n (n is the number, entered by user)

Similar questions