Question
Write a static method called isPrime . This method takes a single int parameter num . The return type is boolean . It returns true
Write a static method called isPrime. This method takes a single int parameter num. The return type is boolean. It returns true if the number is prime, and false, otherwise. You need to write both the method header and the method body.
HINT: You can reuse your code from the previous problem. Compute a list of all of the factors of num. If there are only two unique factors, then num is prime; otherwise num is not prime.
HINT: you can use the size method to get the size of an ArrayList
Sample Input 1:
20
Sample Output 1:
false
Sample Input 2:
1
Sample Output 2:
false
Sample Input 3:
5
Sample Output 3:
true
Sample Input 4:
2
Sample Output 4:
true
Sample Input 5:
3
Sample Output 5:
true
Sample Input 6:
4
Sample Output 6:
false
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
Sure Heres the static method isPrime pu...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Java An Introduction To Problem Solving And Programming
Authors: Walter Savitch
8th Edition
0134462033, 978-0134462035
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App