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

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is the completed Java program NumberDivisorsjava with the numberDivisors f... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!