subject

Sum of Primes JAVA project read 2 strings from the command line; each string will contain an integer. let's call those integers, num1 and num2. write a loop that goes from num1 and num2 looking for prime numbers. if a number if prime then store it in an array of integers, pass this array to a method that returns the sum of all the numbers in the array; you will also need to tell this method how many numbers are in the array. output only the sum of primes. you may assume a maximum of not more than 1000 numbers in the array.
*CODE*
import java. util.*;
class SumPrimes {
// go thru the array primes which has size elements
// total the integer values in primes
// return this total
// the first argument is the array of prime numbers
// the second argument is the number of primes in this array
public static int sumArray(first argument, second argument) {
}
// this method takes an integer, n, and determines if it is prime
// returns true if it is and false if it isn't
// a number is prime if it is only evenly divisible by 1 and itself
// 1 is NOT considered prime
static boolean isPrime(int n) {
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
public static void main(String[] args) {
// define the constant MAX which represents the largest size of the primes array
int num1, num2, numPrime = 0;
// declare an array of the proper data type and size
// convert 1st command line argument from a string to an integer
num1 = Integer. parseInt(args[0]);
// get num2 from the command line
// loop through all integers from num1 to num2
// store those that are prime in the primes array
// keep track of the number of primes - numPrime
// output the sum of all the primes
System. out. println(sumArray(primes, numPrime));
}
}

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, araminaara691
How can a user open a blank presentation? 1.on the file menu, click new, and then click recent templates 2.on the file menu, click new, and then click blank presentation 3. on the view menu, click templates, and then click recent templates 4. on the view menu, click samples, and then click blank presentation
Answers: 1
image
Computers and Technology, 22.06.2019 19:10, sammigrace5820
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, jroy1973
Awide variety of “ apps “ are available to customize devices. which category of app does the word processing software fall into?
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, cdavis379
:you areto design the controller for alight that functions both as an ordinary light and also as a motion activated light and alarm. a. if the manual switch s is on, then the light l is on. b. besides the manual switch, there is a motion detector, m1, which activatesthis light. c.if motion is detected but the light is on anyway because s is on, only then a secondoutput a, an alarm, is turned on. d. the disable switch, d, disables the motion activated light and alarmbut leaves manual control operation of the light using switch s.(i)read the problem statement and clearly identify the inputs and outputs for the circuit you are designing. (ii)create the truth table for this system; include the light, alarm, switch, disable, and the motion sensor.(iii)draw a schematic of this system.
Answers: 1
You know the right answer?
Sum of Primes JAVA project read 2 strings from the command line; each string will contain an integ...

Questions in other subjects: