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, 22.06.2019 02:30
The cm is responsible for overseeing the actions of the crisis management team and coordinating all crisis management efforts in cooperation with disaster recovery and/or business continuity planning, on an as-needed basis
Answers: 1
question
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
question
Computers and Technology, 22.06.2019 23:30
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 1
question
Computers and Technology, 23.06.2019 01:20
Me with this program in c++ ! computers represent color by combining sub-colors red, green, and blue (rgb). each sub-color's value can range from 0 to 255. thus (255, 0, 0) is bright red. (130, 0, 130) is a medium purple. (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (in other word, equal amounts of red, green, blue yield gray).given values for red, green, and blue, remove the gray part. ex: if the input is 130 50 130, the output is: 80 0 80. thus, find the smallest value, and then subtract it from all three values, thus removing the gray.
Answers: 3
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, 23.07.2019 11:20
Questions on the website: 13722367