Find a pseudo code of this program public static boolean is
Find a pseudo code of this program:
{
public static boolean isPrime(long number)
{
for(long i = 2; i <= Math.sqrt(number); i++) //Run the loop from 2 to sqrt(number).
if(number % i == 0) //If the number is divisible by any value of i.
return false; //The number is not prime.
return true; //If all the values exhaust, the number is prime.
}
public static int countPrimesBetween(long start, long end)
{
int count = 0; for(long i = start; i <= end; i++) //For each number in the specified range.
if(isPrime(i)) //If the number is prime.
count++; //Increment the counter.
return count; //Return the count.
}
public static void printLastFivePrimes(long start, long end)
{
int count = 0;
for(long i = end; i >= start && count != 5; i--)
if(isPrime(i))
{
System.out.print(i + \" \");
count++;
}
System.out.println();
}
public static void printFirstFivePrimes(long start, long end)
{
int count = 0; for(long i = start; i <= end && count != 5; i++)
if(isPrime(i))
{
System.out.print(i + \" \");
count++;
}
System.out.println();
}
public static void main(String[] args)
{
long start, end;
System.out.println(\"The number of primes in the range [1, 100] is: \" + countPrimesBetween(1, 100));
System.out.println(\"The number of primes in the range [1, 1000] is: \" + countPrimesBetween(1, 1000));
System.out.println(\"The number of primes in the range [1, 10000] is: \" + countPrimesBetween(1, 10000));
System.out.println(\"The number of primes in the range [1, 100000] is: \" + countPrimesBetween(1, 100000));
System.out.println(\"The number of primes in the range [1, 1000000] is: \" + countPrimesBetween(1, 1000000));
System.out.println(\"The number of primes in the range [1, 10000000] is: \" + countPrimesBetween(1, 10000000));
System.out.println(\"The number of primes in the range [7870000000, 7879999999] is: \" + countPrimesBetween(7870000000, 7879999999));
System.out.println(\"The number of primes in the range [9390000000, 9399999999] is: \" + countPrimesBetween(9390000000, 9399999999));
System.out.println(\"The first 5 primes in the range [1, 100] are: \" + printFirstFivePrimes(1, 100));
System.out.println(\"The last 5 primes in the range [9390000000, 9399999999] are: \" + printLastFivePrimes(9390000000, 9399999999)); } }
Solution
Here is the code as per your requirements.
Pseudo code :
Function isPrime(long number)
 {
 pass in : number to be checked whether it is prime or not
 do while the number from 2 to square root of the number
 find out the reminder
 if the reminder is 0 then pass out : false
 end do
 pass out : true
 }
End Function
 Function countPrimesBetween
 {
 pass in : start number and end number
 do while from starting number to the end number
 call the function isPrime by passing the value
 if returns true value then increment count
 end do
 pass out : count
 }
End Function
 Function printLastFivePrimes
 {
 pass in : start number and end number
 do while from end number to reducing the counter variable by 1 and do this 5 times
 call the function isPrime
 if it returns true value print the number
 and increment the count
 end do
 pass out : nothing
 }
End Function
 Function printFirstFivePrimes(long start, long end)
 {
 pass in : start number and end number
 do while from start number to incrementing the counter variable by 1 and do this 5 times
 call the function isPrime
 if it returns true value print the number
 and increment the count
 end do
 pass out : nothing
 }
End Function
 Function main
 {
 Print \"The number of primes in the range [1, 100] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 100
 Print \"The number of primes in the range [1, 1000] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 1000
 Print \"The number of primes in the range [1, 10000] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 10000
 Print \"The number of primes in the range [1, 100000] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 100000
 Print \"The number of primes in the range [1, 1000000] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 1000000
 Print \"The number of primes in the range [1, 10000000] is: \"
 call the function countPrimesBetween and print the return value by passing 1 and 10000000
 Print \"The number of primes in the range [7870000000, 7879999999] is: \"
 call the function countPrimesBetween and print the return value by passing 7870000000 and 7879999999
 Print \"The number of primes in the range [9390000000, 9399999999] is: \"
 call the function countPrimesBetween and print the return value by passing 9390000000 and 9399999999
 Print \"The first 5 primes in the range [1, 100] are: \"
 call the function printFirstFivePrimes by passing 1 and 100
 print \"The last 5 primes in the range [9390000000, 9399999999] are: \"
 call the function printLastFivePrimes by passing 9390000000 and 9399999999
End function



