First, the question:
Use the following method Printprimes () for questions a–d.
Second, the Code
/******************************************************* * Finds and prints n prime integers * Jeff Offutt, SPR ING 2003 ******************************************************/ Public Static voidPrintprimes (intN) {intCurprime;//Value currently considered for primeness intNumprimes;//Number of primes found so far. BooleanIsPrime;//Is curprime prime? int[] primes =New int[Maxprimes];//The list of prime numbers. //Initialize 2 into the list of primes.primes [0] = 2; Numprimes= 1; Curprime= 2; while(Numprimes <N) {curprime++;//next number to consider ...IsPrime =true; for(inti = 0; I <= numPrimes-1; i++) { //For each previous prime. if(Isdivisable (primes[i],curprime)) {//Found a divisor, curprime is not prime.IsPrime =false; Break;//Out of loop through primes. } } if(isprime) {//Save It!Primes[numprimes] =Curprime; Numprimes++; } } //End while//Print all the primes out. for(inti = 0; I <= numPrimes-1; i++) {System.out.println ("Prime:" +Primes[i]); } } //End Printprimes
Third, the answer
A, the flow chart is as follows:
B. Error may occur when array is out of bounds
C, not through the while loop, so that the initial conditions n=1
D, point coverage
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
Edge Overlay
{(1.2), (2,3), (3,4), (4,5), (5,6), (6,7), (7,5), (6,8), (8,9), (9,10), (9,11), (10,2), (11,2), [2,12], (12,13), [13,14], ( 14,15), (15,13), (13,16)}
Master Path overrides
{(1,2,3,4,5,6,7),
(1,2,3,4,5,9,10),
(1,2,3,4,5,9,11),
(1,2,3,4,5,6,8,9,10),
(1,2,3,4,5,6,8,9,11),
(1,2,12,13,16),
(1,2,12,13,14,15),
(3,4,5,6,8,9,10,2,12,13,14,15),
(3,4,5,6,8,9,10,2,12,13,16),
(3,4,5,9,10,2,12,13,14,15),
(3,4,5,9,11,2,12,13,14,15),
(3,4,5,9,10,2,12,13,16),
(3,4,5,9,10,2,12,13,16),
(3,4,5,6,8,9,11,2,12,13,14,15),
(3,4,5,6,8,9,11,2,12,13,16),
(6,7,5,9,10,2,12,13,14,15),
(6,7,5,9,10,2,12,13,16),
(6,7,5,9,11,2,12,13,14,15),
(6,7,5,9,11,2,12,13,16),
(14,15,13,16),
(13,14,15,13),
(5,6,7,5),
(2,3,4,5,6,8,9,10,2),
(2,3,4,5,6,8,9,11,2),
(2,3,4,5,9,10,2)
(2,3,4,5,9,11,2)}
D. The procedure of judging triangles of the last computer experiment
Because there are three types of triangles, plus a return value that determines whether the input parameter is a positive integer, there are four test requirements for the master path, four use cases (2,2,2), (2,3,3), (2,3,4), ( -2,5,-6).
Can be fully covered, coverage reached 100%;
The third of software testing--path coverage