डाउनलोड पी.डी.एफ. ई-बुक्स
Core Java - Prime Number

विवरण :

कोई विवरण नहीं है |


सोर्स कोड :

import java.util.Scanner;

public class Prime
{
public static void main(String args[])
{ 
int num,i,count=0;
System.out.println("Enter a number: ");
Scanner enter = new Scanner(System.in);
num = enter.nextInt();
   
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1){
System.out.println(num + " is a prime number"); 
}
else{
System.out.println(num + " is not a prime number");
}
   
}
}

आउटपुट :

Enter a number: 
7
7 is a prime number