Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Here is the completed Java program NumberDivisorsjava with the numberDivisors f... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions