Oct 23, 2020 in JAVA
Q:

Write a program to check if a number is prime.

1 Answer

0 votes
Oct 23, 2020

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
Oct 24, 2020 in JAVA
...