Answers for "count number of prime numbers in a given range"

0

how to find prime numbers in a range

class main{
   public static void main(String [] args){
      Scanner sc = new Scanner(System.in); // Scanner function should be imported//
        int a = sc.nextInt();
        int c = 0;
         for(int i=2;i<=a;i++) {
    	      
    	    	 for(int j=2;j<=i;j++) {
                 if(i==j) {  
                      c++;
    	    	   }
                   
    	         if(i%j==0) {  
    	    	   break;
    	    	 }  
    	    	 }
                 }
    	    System.out.println("\nTotal prime numbers ("+a+") - "+c);
  }
}
Posted by: Guest on June-30-2021

Code answers related to "count number of prime numbers in a given range"

Python Answers by Framework

Browse Popular Code Answers by Language