I'm working on this method in Java, which is giving me the factors of a number. I'll be using this method a lot, and I was wondering if there isn't a better way of doing it. Like, with just one loop. Although this code works great and it returns what I expect, I just want to know if there's a better workaround.The method:  public static void main(String[] args) {    System.out.print(Enter a positive number: );    Scanner scanner = new Scanner (System.in);    int number = scanner.nextInt();    int count;    for (int i = 2; i<=(number); i++) {        count=0;        while (number % i == 0) {            number /= i;            count++;        }    if (count == 0) continue;        System.out.println(i+ ** + count);    }}The output I'm expecting:number = 288;2**53**2
Factorizing integers
java;algorithm;primes
Apache Commons Math has a similar function: Primes.primeFactors()Primes.primeFactors(288)Returns a list with the following elements:[2, 2, 2, 2, 2, 3, 3]It open-source, check the implementation (source1, source2) and it contains a lot of optimization. (For example, instead of iterating it all of the numbers, at the beginning it uses an array with the first 512 primes to make it faster.)So it seems faster but it needs some additional work if you want to use your original format. (Converting the list to the P**F format.(See also: Effective Java, 2nd edition, Item 47: Know and use the libraries The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)You don't need the parentheses around number here:for (int i = 2; i<=(number); i++) {This kind of formatting is very hard to read:if (count == 0) continue;    System.out.println(i+ ** + count);It looks like that println would depend on the condition.(According to the Code Conventions for the Java Programming Language if statements always should use braces.)