write a program to print prime numbers between 10 and 99.

write a program to print prime numbers between 10 and 99. First program will print the prime numbers between 1 and 100 2) Second program takes the value of n. If found prime, print the number. Then the next number in the loop is checked, till all numbers are checked.

write a program to print prime numbers between 10 and 99.

Program to display the prime numbers from 1 to 100

It will display the prime numbers between 1 and 100.

class UniqNoDemo
{
   public static void main (String[] args)
   {		
       int i =0;
       int num =0;
       //Empty String
       String  UniqNoDemo = "";

       for (i = 1; i <= 100; i++)         
       { 		  	  
          int myFlag=0; 	  
          for(num =i; num>=1; num--)
	  {
             if(i%num==0)
	     {
 		myFlag = myFlag + 1;
	     }
	  }
	  if (myFlag ==2)
	  {
	     //Appended the Prime number to the String
	     UniqNoDemo = UniqNoDemo + i + " ";
	  }	
       }	
       System.out.println("Prime numbers from 1 to 100 are :");
       System.out.println(UniqNoDemo);
   }
}

Output:

Prime numbers from 1 to 100 are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Program to display prime numbers from 1 to n

import java.util.Scanner;
class UniqNoDemo2
{
   public static void main (String[] args)
   {		
      Scanner scanner = new Scanner(System.in);
      int i =0;
      int num =0;
      //Empty String
      String  UniqNoDemo = "";
      System.out.println("Enter the value of n:");
      int n = scanner.nextInt();
      scanner.close();
      for (i = 1; i <= n; i++)  	   
      { 		 		  
         int myFlag=0; 		  
         for(num =i; num>=1; num--)
         {
	    if(i%num==0)
	    {
		myFlag = myFlag + 1;
	    }
	 }
	 if (myFlag ==2)
	 {
	    //Appended the Prime number to the String
	    UniqNoDemo = UniqNoDemo + i + " ";
	 }	
      }	
      System.out.println("Prime numbers from 1 to n are :");
      System.out.println(UniqNoDemo);
   }
}

Program to find Prime Numbers Between given Interval

Using Static Method
Find Prime Numbers Java Program 1 To N

class UniqNoDemo
{
	public static void main(String arg[])	
	{
 
               System.out.println("Enter a number ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	UniqNoDemoCal(n);
	}
   static void UniqNoDemoCal(int num)
   {
	int flag=0;
	for(int i=1;i<=num;i++)
	{
	   if(num%i==0)
	   {
	        flag++;	        
	   }
	}
	if(flag==2)
	       System.out.println("UniqNoDemo number ");
	else
	System.out.println("Not a UniqNoDemo number ");        
   } 
}

Don't Miss : How To Find The Nth Prime Number In Java?

Find Prime Numbers Between 1 to n
Java Program To Find Prime Numbers Between 1 to n Numbers

class UniqNoDemo
{
	public static void main(String arg[])	
	{
	int i,flag;
               System.out.print("Enter n value : ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
               System.out.println("Prime numbers between 1 to "+n+" are ");
	for(int j=2;j<=n;j++)
	{
	flag=0;
	for(i=1;i<=j;i++)
	{
	   if(j%i==0)
	   {
	        flag++;        
	   }
	}
	if(flag==2)
	       System.out.print(j+"  ");     
	}
	}
}

Prime Number Java Program – Using While Loop

class FindUniqNoDemo
{
	FindUniqNoDemo(int num)
	{
	int flag=0,i=1;
	while(i<=num)
	{
	   if(num%i==0)
	   {
	        flag++;	        
	   }
	i++;
	}
	if(flag==2)
	       System.out.println(num+" is a prime number ");
	else
	System.out.println(num+" is a Not a prime number ");        
	} 
}
class UniqNoDemo
{
	public static void main(String arg[])	
	{
               System.out.println("Enter a number ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	new FindUniqNoDemo(n);
	}
}

Using For Loop

class UniqNoDemo
{
	public static void main(String arg[])	
	{
	int flag=0;
               System.out.println("Enter a number ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	for(int i=1;i<=n;i++)
	{
	   if(n%i==0)
	   {
	        flag++;
	        
	   }
	}
	if(flag==2)
	       System.out.println("prime number ");
	else
	System.out.println("Not a prime number ");	        
	}
}

Using Recursion

class UniqNoDemo
{	
	static int flag=0,i=1;
	int UniqNoDemoOrNot(int num)
	{
		if(i<=num)
		{
		   if(num%i==0)
		   {
		        flag++;                
		   }
		  i++;
		UniqNoDemoOrNot(num);
		}
	     return flag;
	} 
	public static void main(String arg[])	
	{
               System.out.println("Enter a number ");
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	UniqNoDemo p=new UniqNoDemo();
	int c=p.UniqNoDemoOrNot(n);
	if(c==2)
	       System.out.println("prime number ");
	else
	       System.out.println("Not a prime number ");        
	}
}

I hope you get an idea about write a program to print prime numbers between 10 and 99..
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment