in JAVA by
Q:

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

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

0 votes
asked Nov 25, 2020 in JAVA by SakshiSharma
+1 vote
asked Feb 15 in Python by SakshiSharma
0 votes
asked Oct 24, 2020 in JAVA by sharadyadav1986
0 votes
asked Jan 24 in JAVA by rajeshsharma
0 votes
asked May 17, 2020 in Python by sharadyadav1986
...