9 comments:

  1. import java.util.Scanner;

    class Test{

    public static void main(String ar[])
    {

    Scanner sc=new Scanner(System.in);
    int num1,num2,count=0,num;
    System.out.println("Enter Two Numbers");
    num1=sc.nextInt();
    num2=sc.nextInt();

    for(int j=num1;j<=num2;j++){


    num=j;
    for(int i=1;i<=num;i++){
    if(num%i==0)
    count++;
    }
    if(count==2){System.out.println(num+" is a Prime Number");}
    else{System.out.println(num+" is Not a Prime Number");}
    count=0;
    }
    }
    }

    ReplyDelete
  2. import java.util.Scanner;

    class Test
    {

    public static void main(String ar[])
    {

    int i=2,flag=0,upper_limit,lower_limit;
    System.out.print("Enter the lower limit: ");
    Scanner w=new Scanner(System.in);
    lower_limit=w.nextInt();
    System.out.print("Enter the upper limit: ");
    upper_limit=w.nextInt();
    System.out.print("The prime numbers between these two numbers are: ");
    while(lower_limit<upper_limit)
    {
    flag=0;
    i=2;
    while(i<lower_limit)
    {
    if(lower_limit%i==0)
    flag=1;
    i++;
    }
    if(flag!=1)
    {
    System.out.print(lower_limit+"\t");
    }
    lower_limit++;
    }
    }
    }

    ReplyDelete
  3. import java.util.Scanner;
    public class PrimeNumber
    {
    public static void main(String args[])
    {int new1,t=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the Number from where you want to start");
    int Start=scan.nextInt();
    System.out.println("Enter the Number from where you want to end");
    int End=scan.nextInt();
    for(int i=Start;i<=End;i++)
    { new1=i;t=0;
    for(int j=1;j<=new1;j++)
    {
    if(new1%j==0)
    {
    t++;
    }
    }
    if(t==2)
    {
    System.out.println("Prime Number="+new1);

    }
    }

    }
    }

    ReplyDelete
  4. import java.util.Scanner;
    class PrimeN
    {
    public static void main(String Args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the lower limit");
    int a=sc.nextInt();
    System.out.println("enter the upper limit");
    int b=sc.nextInt();
    int count=0;
    int num,i;
    for(i=a;i<b;i++)
    {
    num=i;
    for(int j=1;j<=num;j++)
    {
    if(num%j==0)
    count++;
    }
    if(count==2)
    System.out.println(num+"is prime number");
    else
    System.out.println(num+"is not a prime number");
    count=0;
    }
    }
    }

    ReplyDelete
  5. import java.util.Scanner;

    public class prime1
    {
    public static void main(String ar[])
    {
    Scanner scan = new Scanner(System.in);
    int a,b,num;
    int count;
    System.out.println("enter the first no");
    a = scan.nextInt();
    System.out.println("enter the second no");
    b=scan.nextInt();
    for(int i=a;i<b;i++)
    { num=i;
    count=0;
    for(int j=1;j<=num;j++)
    {
    if(num%j==0)
    {
    count++;
    }
    }
    if(count==2)
    {
    System.out.println("Prime Number="+num);

    }
    }

    }
    }

    output:

    enter the first no
    2
    enter the second no
    13
    Prime Number=2
    Prime Number=3
    Prime Number=5
    Prime Number=7
    Prime Number=11

    ReplyDelete
  6. package forloop;
    import java.util.*;
    public class Twoprime
    {
    public static void main(String args[])
    {
    int i,j,num1,num2,count=0,num;
    System.out.println("enter two numbers");
    Scanner sc=new Scanner(System.in);
    num1=sc.nextInt();
    num2=sc.nextInt();
    for(i=num1;i<=num2;i++)
    {
    num=i;
    for(j=2;j<=num/2;j++)
    {
    if(num%j==0)
    {
    count=1;
    break;
    }
    }
    if(count==0)
    {
    System.out.println("Prime Number is "+num);
    }
    count=0;
    }
    }
    }

    ReplyDelete
  7. import java.util.Scanner;
    class Prime1{
    public static void main(String ar[]){
    Scanner obj=new Scanner(System.in);
    int num1,num2,i,num;
    System.out.println("enter the nos");
    num1=obj.nextInt();
    num2=obj.nextInt();
    for(num=num1;num<=num2;num++){
    for(i=2;i<=num/2;i++){
    if(num%2!=0){
    System.out.println(num);
    break;
    }
    }}
    }
    }

    ReplyDelete
  8. import java.util.*;
    class Prime{
    public static void main(String ar[]){
    Scanner s=new Scanner(System.in);
    int i=2,flag=0,n1,n2;
    System.out.print("Enter number1: ");
    n1=s.nextInt();
    System.out.print("Enter number2: ");
    n2=s.nextInt();
    System.out.print("The prime numbers between"+n1+"and"+2+"are: ");
    while(n1<n2)
    {
    flag=0;
    i=2;
    while(i<n1)
    {
    if(n1%i==0)
    flag=1;
    i++;
    }
    if(flag!=1)
    {
    System.out.print(n1+" ");
    }
    n1++;
    }
    }
    }

    ReplyDelete
  9. import java.util.Scanner;

    class Prime{

    public static void main(String ar[]){
    int num1,num2,n,count=0;
    Scanner scan=new Scanner(System.in);

    System.out.println("Enter Number 1:");
    num1=scan.nextInt();
    System.out.println("Enter Number 2:");
    num2=scan.nextInt();
    for(int j=num1;j<=num2;j++){
    n=j;
    for(int i=1;i<=n;i++){
    if(n%i==0)
    count++;
    }
    if(count==2){
    System.out.println(n+" is a prime number");
    }
    else{
    System.out.println(n+" is not a prime number");
    }
    count=0;
    }
    }
    }

    ReplyDelete