Program To Check Whether A Number Is Prime OR Not | Study Table


 Program To Check Whether 

A Number Is

 Prime OR Not


  • What is 'Prime Number'?
     Ans.     A prime number is a  number that is only divisible by 1
              or itself. Example : 2, 3, 5, 7, 11.


Program


class Prime{

   public static void main(String ARGS[]){

    int no=5, temp=0;

    for(int i=2;i<no-1;i++){
                                                                
      if (no%i==0){

        temp=temp+1;


        }

    }

    if(temp>0){

      System.out.println("No. is not prime");

    }

    else{

      System.out.println("No. is Prime");

    }

    }

}


// So this is a simple program to check whether a given number is Prime or not. 


I hope you have understood the program concept now.

For more  codes and videos visit my Youtube channel :

 https://youtube.com/channel/UC27TQ7zJKapHF78bwvi5iVw

For more Posts based on Programming  visit my Blog:http://studytable10.blogspot.com/

Also, join my telegram:https://t.me/studytable10

     Thanks!!                                              

Comments

Popular posts from this blog

Java Program for Binary to Decimal Conversion | Study Table

Binary Search Program for Java | Study Table

You have accidentally left your suitcase behind when you got off the train. You only realized it after the train left the platform. Write a letter to the station master reporting your loss and request that the suitcase is located and kept till you claim it.