DEV Community

Aafthab Ali Shaik
Aafthab Ali Shaik

Posted on

To Find Whether the Given Number is Prime or Not!!

Image description

Written Code!!

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int count = 0;
        for(int i = 1;i<=s;i++){
            if(s%i==0){
                count+=1;

            }
        }
        if(count==2){
            System.out.println("Its a Prime Number:");
        }else{
            System.out.println("Its Not a Prime Number:");
        }


    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)