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
Clifford created a table using OpenOffice Writer and entered some information into the table. Later, he needed to add more rows
Minchanka [31]

Right click the cell, click add cells & it should say the options (new row above etc.)

4 0
3 years ago
Read 2 more answers
Describe the type of gameplay seen during early video games (ex. Spacewar!, Pong).
Elina [12.6K]
  • Sandbox. ...
  • Real-time strategy (RTS) ...
  • Shooter (FPS and TPS) ...
  • Multiplayer online battle arena (MOBA) ...
  • Role-playing games (RPG, ARPG, and more) ...
  • Simulation and sports.

<em>-</em><em> </em><em>BRAINLIEST</em><em> answerer</em>

3 0
3 years ago
Read 2 more answers
To determine why a computer program started to function differently, Mel should most likely use data to
Amiraneli [1.4K]

Answer:

convince the software company of the issue

Explanation:

3 0
3 years ago
Read 2 more answers
Gwen wants to adjust columns of text that contain money values. Which tab stop option should she choose?
Shtirlitz [24]

Gwen wants to adjust columns of text that contain money values. The tab in excel in the stop option that should she choose is: "The decimal Tab" (Option C)

<h3>

What is the Decimal Tab?</h3>

A Decimal Tab stop is used to align numbers around a decimal point. The decimal point remains in the same location regardless of the amount of digits.

When using this form of tab stop, the numbers must be aligned around a decimal character.

Learn more about excel:
brainly.com/question/25879801
#SPJ1

3 0
1 year ago
A ____ resembles a circle of computers that communicate with each other.
Sidana [21]

Answer:

ring network

Explanation:

In a ring network, the nodes are arranged in a circular pattern where each node is connected to two adjacent nodes. In this topology, any node can communicate with any other node via the intermediaries.

In comparison,

- in a star network every communication needs to pass through a central hub node

- in a bus, each node is connected to a shared linear communication bus.

- in a hierarchical network nodes are organized along a tree structure layout.

4 0
4 years ago
Other questions:
  • Populate a one-dimensional array with the following grades in this order: 90, 61, 74, 42, 83, 51, 71, 83, 98, 87, 94, 68, 44, an
    15·1 answer
  • Refers to the programs or instructions used to tell the computer hardware what to do.
    8·1 answer
  • Technician A says you should measure the parasitic load immediately after the vehicle is turned off. Technician B says you shoul
    10·1 answer
  • Which director has shot a movie in HD? George Lucas, Michael Mann, Michael Moore, none of the above, all of the above
    14·1 answer
  • Together with some anthropologists, you’re studying a sparsely populated region of a rainforest, where 50 farmers live along a 5
    15·1 answer
  • My serious question that needs answering pronto!!!
    11·1 answer
  • To configure a router/modem, what type of IP interface configuration should you apply to the computer you are using to access th
    10·1 answer
  • What are styles? built-in conditional formatting rules formatting applied with the Format Painter defined combinations of format
    15·2 answers
  • The system where the unit of measurement is centimeter
    15·1 answer
  • The FCFS algorithm is particularly troublesome for ____________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!