import java.io.*;
import java.lang.*;
class primeno
{
public static void main(String args[])throws IOException
{
int i,n,p=0,j,m;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Prime Number Checking");
System.out.println("**************");
System.out.println("Enter the m value");
m=Integer.parseInt(d.readLine());
System.out.println("Enter the n value");
n=Integer.parseInt(d.readLine());
System.out.println("Prime Number Checking");
System.out.println("**************");
for(i=m;i<=n;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
p=p+1;
}
}
if(p==0)
System.out.println(+i);
p=0;
}
}
}
-------------
OUTPUT:
-------------
Prime Number Checking
********************
Enter the m value
1
Enter the n value
20
Prime Number Checking
********************
1
2
3
5
7
11
13
17
19
import java.lang.*;
class primeno
{
public static void main(String args[])throws IOException
{
int i,n,p=0,j,m;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Prime Number Checking");
System.out.println("**************");
System.out.println("Enter the m value");
m=Integer.parseInt(d.readLine());
System.out.println("Enter the n value");
n=Integer.parseInt(d.readLine());
System.out.println("Prime Number Checking");
System.out.println("**************");
for(i=m;i<=n;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
p=p+1;
}
}
if(p==0)
System.out.println(+i);
p=0;
}
}
}
-------------
OUTPUT:
-------------
Prime Number Checking
********************
Enter the m value
1
Enter the n value
20
Prime Number Checking
********************
1
2
3
5
7
11
13
17
19
0 comments:
Post a Comment