Answered step by step
Verified Expert Solution
Link Copied!

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

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... 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_2

Step: 3

blur-text-image_3

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

Essential University Physics

Authors: Richard Wolfsonby

3rd Edition Volume 2

321976428, 978-0321976420

More Books

Students also viewed these Algorithms questions