Write a program to check a number is prime or not in java

 Write a program to check a number is prime or not in java

public class PrimeNumber
{
   public static void main(String args[]){
       int num=5,f=0;
       if(num>1){
        for(int i=1;i<=num;i++){
            if(num%i==0){
                f++;
            }
        }
        }
        
        if(f==2){
        System.out.println(num+" is prime number ");
        }else{
        System.out.println(num+" is not prime number ");
        }
    }
}

Output
5 is prime number

Comments

Popular posts from this blog

Calculate Compound Interest in JavaScript

How to make simple bill maker by using python tkinter

Admin Login Page Using HTML and CSS