Write a program to check wheather a program is prime or not, in java
Answers
Answered by
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");
}
}
}
{
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
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");
}
}
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");
}
}
Similar questions