Create a Java program, named NumberDivisors.java. In this program you define a numberDivisors function which takes an
Question:
Create a Java program, named NumberDivisors.java. In this program you define a numberDivisors function which takes an integer n as an input parameter and returns the number of elements that are divisible by n. If n is negative (n<0), it returns 0 and displays "Your integer is not positive". To do this, you complete the Java program, named NumberDivisors.java attached in the places indicated. The main program (main) is provided to you and should not be modified. It introduces 3 integers (100; 17 and -3 for example), invokes the function, and displays the result.
You should get the following display: The number of divisors of 100 is 9 The number of divisors of 17 is 2 Your integer is not positive. The number of divisors of -3 is 0
The Java main:
public class NumberDivisors { /** function that takes an integer n as an input parameter and returns the number of elements that are divisible by n. If n is negative (n<0), it returns 0 */ public static int numberDivisors (int n){ // YOUR CODE }
public static void main(String[] args) {
int N1=100, N2=17, N3=-3;
/* Display*/ System.out.println(); System.out.println("The number of divisors of " + N1 + " is " + numberDivisors(N1)); System.out.println("The number of divisors of " + N2 + " is " + numberDivisors(N2)); System.out.println("The number of divisors of " + N3 + " is " + numberDivisors(N3));
} // end main()
} // end class NumberDivisors
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest