1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Morgarella [4.7K]
3 years ago
15

6.25 (Prime Numbers) A positive integer is prime if it’s divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, b

ut 4, 6, 8 and 9 are not. The number 1, by definition, is not prime. a) Write a method that determines whether a number is prime. b) Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you’ve found all the primes? c) Initially, you might think that n/2 is the upper limit for which you must test to see whether a number n is prime, but you need only go as high as the square root of n. Re- write the program, and run it both ways.
Computers and Technology
1 answer:
faltersainse [42]3 years ago
8 0

Answer:

  1. public class Main {
  2.    public static void main (String [] args) {
  3.        for(int i = 2; i < 10000; i++){
  4.            if(isPrime1(i)){
  5.               System.out.print(i + " ");
  6.            }
  7.        }
  8.        System.out.println();
  9.        for(int i = 2; i < 10000; i++){
  10.            if(isPrime2(i)){
  11.                System.out.print(i + " ");
  12.            }
  13.        }
  14.    }
  15.    public static boolean isPrime1(int n){
  16.      
  17.        for(int i=2; i <= n/2; i++){
  18.            if(n % i  == 0){
  19.                return false;
  20.            }
  21.        }
  22.        return true;
  23.    }
  24.    public static boolean isPrime2(int n){
  25.        for(int i=2; i <= Math.sqrt(n); i++){
  26.            if(n % i  == 0){
  27.                return false;
  28.            }
  29.        }
  30.        return true;
  31.    }
  32. }

<u></u>

Explanation:

Firstly, create the first version of method to identify a prime number, isPrime1. This version set the limit of the for loop as n/2. The for loop will iterate through the number from 2 till input n / 2 and check if n is divisible by current value of i. If so, return false to show this is not a prime number (Line 22 - 26). Otherwise it return true to indicate this is a prime number.

In the main program, we call the isPrime1 method by passing the i-index value as an argument within a for-loop that will iterate through the number 2 - 10000 (exclusive).  If the method return true, print the current i value). (Line 5 - 9)

The most direct way to ensure all the prime numbers below 10000 are found, is to check the prime status from number 2 - 9999 which is amount to 9998 of numbers.

Next we create a second version of method to check prime, isPrime2 (Line 31 - 40). This version differs from the first version by only changing the for loop condition to i <= square root of n (Line 33).  In the main program, we create another for loop and  repeatedly call the second version of method (Line 13 - 17). We also get the same output as in the previous version.

You might be interested in
What is the difference between 1080p and 2k?
professor190 [17]
They have the same  vertical resolution. I can suggest you to watch the video in youtube .<span>https://www.youtube.com/watch?v=uluEEGBHyUE</span>
7 0
3 years ago
Need help asap please​
Fofino [41]
Because you can make it to where they cannot find or see or look or talk or anything on your profile it can cut off Comunication from the person. It can also protect your safety!
6 0
3 years ago
A sinewave has a period (duration of one cycle) of 645 μs. What is the corresponding frequency of this sinewave, in kHz, express
irga5000 [103]

The corresponding frequency of this sinewave, in kHz, expressed to 3 significant figures is: <em>155 kHz.</em>

<u>Given the following data:</u>

  • Period = 645 μs

Note: μs represents microseconds.

<u>Conversion:</u>

1 μs = 1 × 10^{-6} seconds

645 μs = 645 × 10^{-6} seconds

To find corresponding frequency of this sinewave, in kHz;

Mathematically, the frequency of a waveform is calculated by using the formula;

Frequency = \frac{1}{Period}

Substituting the value into the formula, we have;

Frequency = \frac{1}{645\; * \;10^{-6}}

Frequency = 1550.39 Hz

Next, we would convert the value of frequency in hertz (Hz) to Kilohertz (kHz);

<u>Conversion:</u>

1 hertz = 0.001 kilohertz

1550.3876 hertz = X kilohertz

Cross-multiplying, we have;

X = 0.001 × 1550.39

X = 155039 kHz

To 3 significant figures;

<em>Frequency = 155 kHz</em>

Find more information: brainly.com/question/23460034

5 0
3 years ago
Which of the following application delivery methods requires Internet access?
morpeh [17]

Answer:Cloud hosted

Explanation:

3 0
3 years ago
Two devices are connected to the Internet and communicating with one another. A squirrel chews through one of the wires in the n
bearhunter [10]

Answer:

Fault-Tolerance

Explanation:

Fault tolerance refers to the ability of a system (computer, network, cloud cluster, etc.) to continue operating without interruption when one or more of its components fail.

5 0
4 years ago
Other questions:
  • Depending on the manufacturer of the bios, what two different post beep code sequences indicate a memory error?
    11·1 answer
  • A newspaper publishes a negative editorial on how local politicians are dragging their feet in building a new bridge. Select the
    5·2 answers
  • What are the disadvantages of cloud computing?
    9·1 answer
  • Attribute that contains only digits as a character data type instead of a numeric data type
    8·1 answer
  • Why does fiber optic communication technology have a significant security advantage over other transmission technology? higher d
    6·1 answer
  • Intuitively, which of the following would happen to e⃗ net if d became very large?
    6·1 answer
  • When a member function is defined outside of the class declaration, the function name must be qualified with theWhen a member fu
    14·1 answer
  • Encryption is the key to keeping your personal information secure online.<br><br> True<br><br> False
    11·1 answer
  • What is the most popular type or method of guaranteed reservation where booking transactions will be charged automatically?
    7·1 answer
  • What is an example of value created through the use of Deep Learning?​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!