Trying to Find numbers that have 4 factors with Java Program but Output is Wrong

I am trying to make a Java program that lets the user know if their number is a RSA number (or has 4 factors). This program keeps showing me the wrong output. For example, when the range is 11-15, instead of outputting 2, it outputs 0. Please advise.

import java.util.Scanner;
  public class Main {
  public static void main(String[] args) {

    Scanner in = new Scanner(System.in);


    int minimum = in.nextInt();

    int maximum = in.nextInt();

    int numOfFactors = 2;
    
    int numRSA = 0;

    int number = minimum;

    while (number>= minimum && number <= maximum){ 
        // condition for nonprime number
            for (int i = 2; i <= number/2; ++i) {
              if (number % i == 0 && number>=minimum && number<maximum) {
                numOfFactors = numOfFactors + 1;
              }
            }
          if (numOfFactors == 4){
            numRSA = numRSA + 1;
        }
          number= number + 1;
    }
    

    System.out.println("The number of RSA numbers between " +minimum + " and " +maximum+ " is " +numRSA);

  }
}


Read more here: https://stackoverflow.com/questions/66328277/trying-to-find-numbers-that-have-4-factors-with-java-program-but-output-is-wrong

Content Attribution

This content was originally published by Henry at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: