I would like to know why this java program is not working to find the prime factors of a number. I have seen many solutions on this site and elsewhere but I want to know why this approach is not sufficient as it returns only 1 as an output? The first "if statement" handles numbers from 1 and lower to return -1 (invalid value), thanks.
public class PrimeFactors{
public static void main(String[] args) {
System.out.println(getPrimeFactors(4));
}
public static int getPrimeFactors(int number) {
if (number <= 1) {
return -1;
}
for (int i = 1; i <= number; i++) {
if (number % i == 0) {
return i;
}
}
return number;
}
}