Question: Draw the control flow graph for the printPrimes ( ) method. static String printPrimes ( int n ) { int curPrime; / / Value currently
Draw the control flow graph for the printPrimes method.
static String printPrimes int n
int curPrime; Value currently considered for primeness
int numPrimes; Number of primes found so far.
boolean isPrime; Is curPrime prime?
int primes new int ; The list of prime numbers.
String str ;
Initialize into the list of primes.
primes ;
numPrimes ;
curPrime ;
while numPrimes n
curPrime; next number to consider
isPrime true;
for int i ; i numPrimes; i
for each previous prime.
if isDivisible primesi curPrime
Found a divisor, curPrime is not prime.
isPrime false;
break; out of loop through primes.
if isPrime
save it
primesnumPrimes curPrime;
numPrimes;
End while
Print all the primes out.
for int i ; i numPrimes; i
str primesi ;
System.out.printlnstr;
return str;
end printPrimes
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
