To find the factors, repeat the following until number is equal to 1:
▪ Start with a factor of 2 each time through the loop
▪ As long as number is not divisible by the current factor (result from modulus is not 0), increase the
factor by 1
▪ Once you've found a factor (result from modulus is 0), add the factor to your list (add it to the String) and
then divide number by the factor
◦ Return the String that contains all the factors (separated by spaces)
public static String findPrimeFactorization(int number)
{
String factorise = " ";
int i;
for(i = 2; i < number; i++){
while(number % i == 0)
{
factorise = factorise + " " + i);
number /= i;
}
}
return factorise;
}
I am getting an error:
Syntax error on token ")", delete this token
What should I do?
zafarj, on 01 July 2011 - 08:09 PM, said:
The question is to find all the factorization of number.
To find the factors, repeat the following until number is equal to 1:
▪ Start with a factor of 2 each time through the loop
▪ As long as number is not divisible by the current factor (result from modulus is not 0), increase the
factor by 1
▪ Once you've found a factor (result from modulus is 0), add the factor to your list (add it to the String) and
then divide number by the factor
◦ Return the String that contains all the factors (separated by spaces)
I am getting wrong answer:
2 2 5 5
What should I do?
To find the factors, repeat the following until number is equal to 1:
▪ Start with a factor of 2 each time through the loop
▪ As long as number is not divisible by the current factor (result from modulus is not 0), increase the
factor by 1
▪ Once you've found a factor (result from modulus is 0), add the factor to your list (add it to the String) and
then divide number by the factor
◦ Return the String that contains all the factors (separated by spaces)
public static String findPrimeFactorization(int number)
{
String factorise = " ";
int i;
for(i = 2; i < number; i++){
while(number % i == 0)
{
factorise = factorise + " " + i;
number /= i;
}
}
return factorise;
}
I am getting wrong answer:
2 2 5 5
What should I do?

New Topic/Question
Reply


MultiQuote



|