Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please include comments as well. Your help would be very much appreciated. Write

ID: 3531183 • Letter: P

Question



Please include comments as well. Your help would be very much appreciated.

Write an algorithm to find all prime numbers up to some limit N. For this algorithm, consider every number from 2 up to N. If it is a prime, you include it in the list. To test whether a number m is a prime number you simply divide it by each of the numbers 2, 3 ... m-1; if any of these divisions is without remainder, then m is not prime, otherwise it is. Your program should take two command line arguments (the algorithm number and N) and output the primes using System.out.println and the timing data using System.err.println - so you could run your program like this: Java-jar Primes.jar 117 and get an output like this: 2 3 5 7 11 13 17 1 The first 7 numbers are prime numbers less than/equal to 17, the last number is the time taken to run the algorithm.

Explanation / Answer

Please rate with 5 stars :)