Program for Check the Given Num Prime Or NOT::
class PrimeNo
{
public static void main(String[] args)
{
int num=Integer.parseInt(args[0]);
int flag=0;
"
{
if(num%i==0)
{
System.out.println(num+" is not a prime num");
flag=1;
break;
}
}
if(flag==0)
{
System.out.println(num+" is a prime num");
}
}
}
Program for Find the Prime Numbers up to Given Number:
import java.util.*;
class PrimeNum2
{
public static void main(String[] args)
{
int i,j,s=0,d=0;
int n;
Scanner sn=new Scanner(System.in);
System.out.println("Enter the Number YOu Want::");
n=sn.nextInt();
"for(i=1;i<=n;i++)">
{
s=0;
"for(j=1;j<=i;j++)"
{
if(i%j==0)
s=s+1;
}
if(s==2)
{
System.out.println(i);
d=d+1;
}
}
System.out.println("The Number Of Prime Numbers Are==:"+d);
}
}
Program for Find the AlterNative Prime Numbers up to Given Number:
import java.util.*;
class PrimeNum2
{
public static void main(String[] args)
{
int i,j,s=0,d=0;
int n;
Scanner sn=new Scanner(System.in);
System.out.println("Enter the Number YOu Want::");
n=sn.nextInt();
System.out.println("AlterNative Prime NUmber:");
"for(i=1;i<=n;i++)">
{
s=0;
"for(j=1;j<=i;j++)"
{
if(i%j==0)
s=s+1;
}
if(s==2)
{
d=d+1;
if(d%2==0)
System.out.println(i);
}
}
System.out.println("The Number Of Prime Numbers Are==:"+d);
}
}
No comments:
Post a Comment