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

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
In the context of it jobs in the information systems field. a is responsible for database design and implementation
Answers: 3
question
Computers and Technology, 23.06.2019 01:30
How do you set up a slide show to play continuously, advancing through all the slides without requiring your interaction? a. click set up slide show, and then select the loop continuously until ‘esc' and show without narration options. b. click set up slide show, and then select the loop continuously until ‘esc' and use timings, if present options. c. click set up slide show, and then select the show presenter view and use timings, if present options. d. click set up slide show, and then select the show without animation and browsed at a kiosk (full screen) options.
Answers: 3
question
Computers and Technology, 24.06.2019 00:50
Which player type acts on other players? a. killer b. achiever c. explorer d. socializer
Answers: 1
question
Computers and Technology, 24.06.2019 08:20
Evaluate the scenario below and indicate how to handle the matter appropriately. situation: michael received an e-mail from what he thought was his doctor’s office, requesting his social security number. since he had just been in to see his doctor last week, he replied to the e-mail with his social security number.
Answers: 2
You know the right answer?
Sum of Primes JAVA project read 2 strings from the command line; each string will contain an integ...
Questions
question
Mathematics, 19.05.2021 15:00
question
Mathematics, 19.05.2021 15:00
question
Mathematics, 19.05.2021 15:00
question
Physics, 19.05.2021 15:00
Questions on the website: 13722360