Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Business Management Expert

Need guidance real quick. How can I modify this program to print out all the integers that meet the requirements not just one of them. At the moment the program just find the largest number of divisors for one integer but I would like to print out all the integers between 1 and 1000 that have the maximum number of divisors.

/**
  * This program finds an integer between 1 and 10000 that has
  * the largest number of divisors.  It prints out the maximum
  * number of divisors and an integer that has that many divisors.
 */

public class MostDivisors {

 public static void main(String[] args) {

   int N;            // One of the integers whose divisors we have to count.
   int maxDivisors;  // Maximum number of divisors seen so far.
   int numWithMax;   // A value of N that had the given number of divisors.

   maxDivisors = 1;  // Start with the fact that 1 has 1 divisor.
   numWithMax = 1;

   /* Process all the remaining values of N from 2 to 10000, and
      update the values of maxDivisors and numWithMax whenever we
      find a value of N that has more divisors than the current value
      of maxDivisors.
   */

   for ( N = 2;  N <= 10000;  N++ ) {

       int D;  // A number to be tested to see if it's a divisor of N.
       int divisorCount;  // Number of divisors of N.

       divisorCount = 0;

       for ( D = 1;  D <= N;  D++ ) {  // Count the divisors of N.
          if ( N % D == 0 )
             divisorCount++;
       }

       if (divisorCount > maxDivisors) {
          maxDivisors = divisorCount;
          numWithMax = N;
       }

   }

   System.out.println("Among integers between 1 and 10000,");
   System.out.println("The maximum number of divisors is " + maxDivisors);
   System.out.println("A number with " + maxDivisors + " divisors is " + numWithMax);

   } // end main()

}

Business Management, Management Studies

  • Category:- Business Management
  • Reference No.:- M93129121
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Business Management

What are the moralethical implications on the use of power

What are the moral/ethical implications on the use of power to influence outcomes? Do ends justify means when exerting power? Support your answer.

Based on land minerals and natural resources labor and

Based on land, minerals and natural resources, labor and entrepreneurial innovation, which country do you feel has the greatest long-term potential China or Russia.

What are some costing and financial strategies for

What are some costing and financial strategies for manufacturing and service companies?

Do you agree with the statement cruel system is the one

Do you agree with the statement: "cruel system is the one that doesn't tell anybody where they stand" (in term of designing competitive organization)

Explain and discuss the following quotepoliticians can be

Explain and discuss the following quote: "Politicians can be strange. They have been calling for the breakup of firms as diverse as energy companies and tech giants like Microsoft and Google because they believe these co ...

Differentiate between a price taker and a price setterif

Differentiate between a price taker and a price setter. If you were the manager of a primary care clinic, which strategy would you choose and why.

When it is appropriate to use the trade-off process what

When it is appropriate to use the trade-off process. What conditions apply, and the technical evaluation criteria that might be used?

Why might incomes of 1 a day and 2 a day underestimate the

Why might incomes of $1 a day and $2 a day underestimate the value of the goods and services that these households actually consume? Please answer.

When applying industry analysis and organizational

When applying industry analysis and organizational structure determine when past industry performance is a good indicator of future profitability and when is it not a good indicator? and why, please explain the logic so ...

The decision to globalize operations is very complex and

The decision to globalize operations is very complex and not without risks. Chose a company that has not yet globalized and answer the following: Describe how would you decide if the best option was to expand globally An ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As