Computer Science, asked by NamelessWonder, 1 year ago

Write a program to check wheather a program is prime or not, in java

Answers

Answered by shukoor
3
public class prime_check
{
public static void main (int n )
{
int c=0;
for ( int f=1;f<=n;f++)
{
if ( n%f==0)
c++
}
if ( c<=2)
{
System.out.println ( "prime no");
}
else
{
System.out.println ("not");
}
}
}


NamelessWonder: thanks!
Answered by duragpalsingh
4
A program to check whether a program is prime or not:

PrimeNo{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int flag=0;
for(int i=2;i<num;i++){
if(num%i==0)
{
System.out.println(num+" is not a Prime Number");
flag = 1;
break;
}
}
if(flag==0)
System.out.println(num+" is a Prime Number");
}
}

duragpalsingh: thanks for marking brainliest
Similar questions