Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a static method called checkPrime that takes an integer n as a parameter and that checks how many factors n has, returning true if

Write a static method called checkPrime that takes an integer n as a parameter and that checks how many factors n has, returning true if it is prime (exactly 2 factors) and returning false otherwise. Recall that a factor is a number between 1 and n that goes evenly into n and that prime numbers are those that have exactly two factors (1 is not a prime). So if we make the following call:

boolean test = checkPrime(24);

The method should produce the following two lines of output:

factors of 24 = 1, 2, 3, 4, 6, 8, 12, 24 Total factors = 8

and the variable test would be set to false because this number does not have exactly 2 factors.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Sure Heres a possible implementation of the checkPrime method public static boolean checkPrimeint n ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions