Я пишу метод для факторизации числа, и по какой-то причине, когда я пытаюсь напечатать фактор А, он говорит, что он не распознан, какие-либо предложения?
public static void factorize(int n){
if (n % 2 == 0){ //If number is even
int factorA = 2;
int factorB = n/2;
}else{ //If number is odd
int halfLine = n/2; //Only variables that are even will be factors greater than half of them, this case is only for odd integers
int smallestFactorOdd = 3;
while (smallestFactorOdd < halfLine){ //Until you've found the smallest factor for add variables
if (n % smallestFactorOdd == 0){ //If smallestFactorOdd is a factor of n
int factorA = smallestFactorOdd;
int factorB = n/smallestFactorOdd;
}else{
smallestFactorOdd += 2;
}
}
}
System.out.println(factorA);
}
Обновленный код (ошибка все еще принимается):
public static void factorize(int n){
int factorA;
int factorB;
if (n % 2 == 0){ //If number is even
factorA = 2;
factorB = n/2;
}else{ //If number is odd
int halfLine = n/2; //Only variables that are even will be factors greater than half of them, this case is only for odd integers
int smallestFactorOdd = 3;
while (smallestFactorOdd < halfLine){ //Until you've found the smallest factor for add variables
if (n % smallestFactorOdd == 0){ //If smallestFactorOdd is a factor of n
factorA = smallestFactorOdd;
factorB = n/smallestFactorOdd;
}else{
smallestFactorOdd += 2;
}
}
}
System.out.println(factorA);
System.out.println(factorB);
}