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 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 22:00
Jackson, who works in the finance department of a company, is holding a seminar for other employees on how to file taxes. only three employees sign up to attend the seminar. which device can he use to share his presentation with a group of three employees?
Answers: 1
question
Computers and Technology, 24.06.2019 16:30
What is the item which could be matched with a statement below? software installed on a computer that produces pop-up ads using your browser an example of social engineering malware loads itself before the os boot is complete type of spyware that tracks your keystrokes, including passwords windows key + l the practice of tricking people into giving out private information or allowing unsafe programs into the network or computer when someone who is unauthorized follows the employee through a secured entrance to a room or building a type of malware that tricks you into opening it by substituting itself for a legitimate program a computer that has been hacked, and the hacker is using the computer to run repetitive software in the background without the user's knowledge an infestation designed to copy itself repeatedly to memory, on drive space, or on a network
Answers: 1
question
Computers and Technology, 25.06.2019 00:00
To remove text from a specific location and keep it to use again, you should select
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
question
Biology, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
Computers and Technology, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
Mathematics, 18.12.2020 14:00
question
History, 18.12.2020 14:00