Answer to Question #300541 in Java | JSP | JSF for rim

Question #300541

Write a function that accepts an integer argument and checks if the number is

prime. Write a function that keeps count of number of times it’s been invoked


1
Expert's answer
2022-02-21T01:27:26-0500
public class Main {
    public static int count = 0;

    public static void count() {
        count++;
    }

    public static boolean isPrime(int value) {
        count();
        for (int i = 2; i < value + 1; i++) {
            for (int j = i * i; j < value + 1; j += i) {
                if (j == value) {
                    return false;
                }
            }
        }
        return true;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS