subject

Consider the task of writing a method named countfactors that accepts an integer (assumed to be positive) as its parameter and returns a count of its positive factors. for example, the six factors of 12 are 1, 2, 3, 4, 6, and 12, so the call countfactors(12) should return 6. the following is an attempt at solving the problem, but it is incorrect. determine what is wrong with the code, and submit a corrected version that works properly. public static int countfactors(int n) {
for (int i = 1; i < = n; i++) {
if (n % i == 0) { // a factor
return i;
}
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:00
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 3
question
Computers and Technology, 23.06.2019 20:30
Column a of irma’s spreadsheet contains titles for each row, but her document is too big and will be printed three pages across. she wants to be sure that every page will be understood. what can irma do to with this problem?
Answers: 3
question
Computers and Technology, 23.06.2019 22:00
Jackson, who works in the finance department of a company, is holding a seminar for other employees on how to file taxes. only three employees sign up to attend the seminar. which device can he use to share his presentation with a group of three employees?
Answers: 1
You know the right answer?
Consider the task of writing a method named countfactors that accepts an integer (assumed to be posi...
Questions
question
Mathematics, 27.01.2021 21:00
question
Mathematics, 27.01.2021 21:00
question
Mathematics, 27.01.2021 21:00
question
Spanish, 27.01.2021 21:00
question
Mathematics, 27.01.2021 21:00
question
Mathematics, 27.01.2021 21:00
Questions on the website: 13722363