Need assistance with this JAVA program please Write a method
Need assistance with this JAVA program, please. Write a method named sumInts that can take a variable number of int arguments and return the sum of these arguments. The ints to be summed up must be entered as COMMAND LINE ARGUMENTS. In the main method, display the ints that were entered on the command line. Then execute sumInts and display the sum it returns.
SAMPLE OUTPUT:
Passing [1, 2, 3, 4, 5]
Sum is 15
Passing [10, 20, 30]
Sum is 60
Solution
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct thread_data {
int n;
int result; } thread_data;
/* Inefficiently, compute successive prime numbers.
Return the nth prime number. */
void* compute_prime (void * arg) {
/* dereference the parameter */
thread_data * tdata = (thread_data *)arg;
int n = tdata->n;
int candidate = 2;
while (true) {
int factor;
int is_prime = true;
/* test primality by successive division. */
for (factor = 2; factor < candidate; ++factor)
if (candidate % factor == 0) {
is_prime = false;
break;
}
/* is prime number we\'re looking for? */
if (is_prime) {
if (--n == 0) {
/* define the result */
tdata->result = candidate;
pthread_exit(NULL);
}
}
++candidate;
}
}
int main ()
{
pthread_t tid;
thread_data tdata;
time_t t;
/* intialize random number generator */
srand((unsigned) time(&t));
tdata.n=rand() % 5000;
printf(\"The %dth prime number\", tdata.n);
/* start the thread, up to \"tdata.n\" */
pthread_create (&tid, NULL, compute_prime, (void *)&tdata);
/* wait for the thread to complete */
pthread_join (tid, NULL);
/* print the computed prime */
printf(\" is %d.\ \", tdata.result);
}
}

