Problem: Number of Factors
Problem Statement
A factor for a given value is an integer
that evenly divide the value (i.e. a divisor with no remainder). This
problem asks you to calculate the number of factors for given number. For the purpose of this problem, the number
itself or 1 are not counted as factors. That means that a prime number
will have 0 factors.
Given an integer, write a function that returns the number of factors for a
number..
Definition
- Class: Count
- Function/Method: numFactors
- Parameters: int
- Returns: int
- Method signature (see below)
public int numFactors(int n)
Class
public class Count
{
public int numFactors(int n)
{
// TODO: fill in numFactors
}
}
Constraints
Examples
2
Returns: 0
32
Returns: 4
The factors are 2, 4, 8, and 16.
Comments?