package com.kapish;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//Prime Number
Scanner sc= new Scanner(System.in); //System.in --> input from keyboard
System.out.print("Enter a Integer: ");
int a = sc.nextInt();//reads number
//For Making it Efficient
int b = (a/2)+1;
int notp = 1;
int f =0;
//for loop to find who is dividing it
for(int i = 2; i <= b; i++)
{
// condition for non Prime number
if(a % i == 0) {
f=i;
notp=1;
break;
}
else{
notp=0;
}
}
if (notp==0){
System.out.println(a+"ya Boy! It's Prime number : ");
}
else{
System.out.println("Not A Prime number since its divisble by "+f);
}
}
}
Tuesday, August 4, 2020
New
Best WAP to find whether a given number is prime or not.
About Kapish
Save Your Time With the Time Saving And Information Rich Content and keep Smiling
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment