Question

In: Computer Science

The class FindFac discussed in this chapter prints the factors of all numbers from 1 to...

The class FindFac discussed in this chapter prints the factors of all numbers from 1 to 100. Modify this class so that, instead of stopping at 100, it keeps going until it finds a number with exactly nine factors. This is a Java program

Solutions

Expert Solution

public class FindFac {
    public static void main(String[] args) {
        for(int i = 0;i<=100;i++){
            System.out.print("Factors of "+i+" are: ");
            for(int j = 1;j<=i;j++){
                if(i%j==0){
                    System.out.print(j+" ");
                }
            }
            System.out.println();
        }
    }
}

//////////////////////////////////////////////////////////////////////////////////////

public class FindFac {
    public static void main(String[] args) {
        int count;
        for(int i = 0;i<=100;i++){
            count = 0;
            System.out.print("Factors of "+i+" are: ");
            for(int j = 1;j<=i;j++){
                if(i%j==0){
                    System.out.print(j+" ");
                    count++;
                }
            }
            System.out.println();
            if(count==9){
                break;
            }
        }
    }
}

Related Solutions

In addition to the five factors discussed in the chapter, dividends also affect the price of...
In addition to the five factors discussed in the chapter, dividends also affect the price of an option. The Black–Scholes option pricing model with dividends is:    C=S × e−dt × N(d1) − E × e−Rt × N(d2)C=S⁢ × e−dt⁢ × N(d1)⁢ − E⁢ × e−Rt⁢ × N(d2) d1= [ln(S  /E ) +(R−d+σ2 / 2) × t ] (σ − t√) d1= [ln(S  /E⁢ ) +(R⁢−d+σ2⁢ / 2) × t ] (σ⁢ − t)  d2=d1−σ × t√d2=d1−σ⁢ × t   ...
In addition to the five factors discussed in the chapter, dividends also affect the price of...
In addition to the five factors discussed in the chapter, dividends also affect the price of an option. The Black-Scholes option pricing model with dividends is: C=S × e−dt × N(d1) − E × e−Rt × N(d2) d1= [ln(S  /E ) +(R−d+σ2 / 2) × t ] (σ − t√)  d2=d1−σ × t√ All of the variables are the same as the Black-Scholes model without dividends except for the variable d, which is the continuously compounded dividend yield on the...
Write a c++ program that prints the count of all prime numbers between A and B...
Write a c++ program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = Any 5 digit unique number B = A + 1000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Write a program that prints the count of all prime numbers between A and B (inclusive),...
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7,...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are evenly divisible by all numbers between 5 and 15 (inclusive). Do not use any libraries besides stdio.h. Need it in 10 minutes, please.
A number of factors affecting price sensitivity are discussed in this chapter. Provide some examples
A number of factors affecting price sensitivity are discussed in this chapter. Provide some examples of the application of these factors in the hospitality or travel businesses.
/ File: temperature.cxx // This program prints a table to convert numbers from one unit to...
/ File: temperature.cxx // This program prints a table to convert numbers from one unit to another. // The program illustrases some implementation techniques. #include // Provides cout #include // Provides setw function for setting output width #include // Provides EXIT_SUCCESS #include // Provides assert function using namespace std; // Allows all standard library items to be used double celsius_to_fahrenheit(double c) // Precondition: c is a Celsius temperature no less than absolute // zero (-273.16). // Postcondition: The return value...
in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
Write a class to accept a sentence from the user and prints a new word in...
Write a class to accept a sentence from the user and prints a new word in a terminal formed out of the third letter of each word. For example, the input line “Mangoes are delivered after midnight” would produce “neltd”. Program Style : Basic Java Programming
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT