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
You use the _____ sheet in the format cells dialog box to position data in a cell by centering it, for example.​
Oliga [24]
You use the Alignment sheet in the format cells dialog box to position data in a cell by centering it, for example. Generally along the middle branch is a line or centerline of the definite pipeline on a scale of whatever is indicated.
3 0
3 years ago
I have to make a online presentation, which program is the best
LiRa [457]
If you want an online presentation, I think you mean by a website.
Best thing you can find is Google Slides.
if you want a program,
LibreOffice is your best bet. It is completely free and it is for Linux, Windows and possibly Mac.
4 0
3 years ago
Read 2 more answers
In the context of data quality management tools, _____ software is one that gathers statistics, analyzes existing data sources a
Dimas [21]

Answer:

Data-profiling software

Explanation:

Data-profiling software -

It refers to the software , that helps to collect the data or information from a particular existing source and performed it analysis , is referred to as a Data-profiling software .

The software helps to determine information about a topic , or analyse the pattern , for the process of comparison etc.

Hence , from the given information of the question ,

The correct answer is Data-profiling software .

5 0
3 years ago
ASCII contains codes for most of the languages in use today.<br><br> True or False
Harrizon [31]

False, Dont take my word but google is your friend

5 0
3 years ago
It is important to give the health and safety experience to new or inexperienced workers, including those that have been away fr
Phoenix [80]

Answer:

a. training

Explanation:

"Training" is crucial when it comes to new workers or workers who are coming back after a long vacation or whatever reason. The risk of injuries and making mistakes is high for new workers because they are still adjusting to the company's processes. This is similar to a baby who's learning to walk. The baby makes several slips before mastering the skill. For a worker who has been away from the workforce, training should also be given because that worker needs to freshen up his skills and relearn what he needs to grasp before working.

This situation is especially true to <em>construction workers </em>who work under contractual projects. This means, they always have to be trained every time about their new jobsite before even working.

6 0
4 years ago
Other questions:
  • After applying transitions to his presentation, Omar uses the Slide Show feature to view the them. He notices that the transitio
    9·2 answers
  • Which of these is NOT an advantage of the impact of computer careers.
    9·1 answer
  • When should an individual consider entering parenthood?
    5·1 answer
  • ____ port is a connection in which eight data lines transmit an entire byte of data at one moment in time.
    12·1 answer
  • Cell references in a formula are called _____.<br> a. assumptionsc. numbersb. valuesd. content
    11·1 answer
  • What effect does the interconnectedness of modern media have on society?
    14·2 answers
  • As related to the use of computers, ____ is defined as gaining unauthorized access or obtaining confidential information by taki
    10·1 answer
  • Which one of these is NOT an indicator that an email is spam?
    5·1 answer
  • 5.9.5 Fibonacci <br><br> Y’all I’m struggling here do any of you have the code?
    12·1 answer
  • A(n) ____ is a live internet presentation that supports interactive communications between the presenter and the audience.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!