Skip to content

Instantly share code, notes, and snippets.

@w3farid
Created March 4, 2016 04:45
Show Gist options
  • Save w3farid/183f817333aaead2ebca to your computer and use it in GitHub Desktop.
Save w3farid/183f817333aaead2ebca to your computer and use it in GitHub Desktop.
Giving input in runtime and checked whether it is prime on not prime?
import java.util.Scanner;
public class PrimeNumberChecker {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int a=s.nextInt();
int i=1;
int count=0;
while (a>0) {
do{
if(a%i==0){
count++;
}
i++;
}while(i<=a);
if(count==2){
System.out.println("prime");
}else {
System.out.println("not prime");
}
a=s.nextInt();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment