Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a method that will determine whether an input integer has three prime factors. 1. Try to divide by 2 if true counter++ 2.
Write a method that will determine whether an input integer has three prime factors. 1. Try to divide by 2 if true counter++ 2. A loop from 3 to n/2 (+2): m If m is prime n%m == 0 Counter++ a. b. c. If the value of counter is higher than 3 d. Return false (or break) 3. If the value of counter is 3 then return true 4. Else return false public static boolean triPrimeFactors (int num) { int counter = 0; if (num%2== 0) counter++; for (int i = 3; i < int(num/2)+1; i = i+2) { } if (num % i == 0 && isPrime(i )) counter++; if (counter > 3) return false; } if (counter == 3) return true; else return false; } public static boolean triPrimeFactorsV2 (int num) { int counter = 0: if (num%2== 0) counter++; int i =3: while (i < int(num/2)+1) { if (num % i == 0 && isPrime(i)) counter++; if (counter > 3) return false; i=i+2; } if (counter == 3) return true; else return false:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Method 1 triPrimeFactors java public sta...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 Started