0 votes
in JAVA by

Write a program to check if a number is prime.

1 Answer

0 votes
by

Write a program to check if a number is prime.

import java.util.Scanner; 

public class star { 

     public static void main(String[] args) { 

         Scanner sc=new Scanner(System.in); 

         int n=sc.nextInt(); 

         int count=0; 

         for (int i=1;i<=n;i++) 

         { 

             if (n%i==0) 

             count++; 

         } 

         if (count==2) 

         System.out.println("Prime"); 

         else 

         System.out.println("Not Prime"); 

        } 

🔗Reference: stackoverflow.com

🔗Source: Java Interview Questions and Answers

Related questions

0 votes
asked Jan 7 in C Plus Plus by GeorgeBell
0 votes
asked Mar 16, 2021 in JAVA by Robindeniel
...