-
Method to Count Factors
- Signature:
public static int getFactorCount(int number)
- Description:
This method should return the count of factors of the given number.
- Signature:
-
Method to Check if a Number is Prime
- Signature:
public static boolean isPrime(int factorCount)
- Description:
This method should returntrue
if the given factor count indicates a prime number (exactly 2 factors), andfalse
otherwise.
- Signature:
-
Method to Retrieve All Factors
- Signature:
public static int[] getFactors(int number, int factorCount)
- Description:
This method should return an integer array containing all the factors of the given number.
- Signature:
-
Main Method
- Signature:
public static void main(String[] args)
- Description:
This method should:- Prompt the user to input a number.
- Use
getFactorCount
to calculate the total number of factors and print the result. - Use
isPrime
to check if the number is prime and printtrue
for prime orfalse
otherwise. - Use
getFactors
to retrieve all the factors of the number and print them.
- Signature:
If the user enters the number 10
, the program should display:
If the user enters the number 2
, the program should display:
If the user enters the number 17
, the program should display:
If the user enters the number 20
, the program should display:
- The program should handle any positive integer input.
- Provide meaningful error messages for invalid inputs (e.g., negative numbers or non-numeric inputs).
- A factor of a number is an integer that divides the number without leaving a remainder.
- A prime number is a number with exactly 2 factors:
1
and the number itself. - Use arrays to store the factors of the number.