1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
choli [55]
3 years ago
13

Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is

not a divisor of any integer, 1 divides every number, and n divides itself.
Computers and Technology
1 answer:
Helen [10]3 years ago
4 0

Answer:

public int[] factors(int n)

{

int arr[]=new int[n];

int count=0;

for(int i=1;i<=n;i++)

if(n%i==0)

{

arr[count]=i;

count++;

}

return arr;

}

Explanation:

Factors are the numbers you multiply to get another number. For instance, factors of 15 are 3 and 5, because 3×5 = 15.

In the program , we have an array of length N to store the factors.

Since we don't know the number of factors of N, so we have taken size of upper bound N to store list of factors in the array arr.

Within the loop the number gets divide by Integers from 1 to that number until result is 0. If it is 0, that number is stored in array.

You might be interested in
Complete the following method named replaceEvens that receives the parameter numbers which is an array of integers. The method m
Taya2010 [7]

Answer:

Following are the method definition to this question:

public class Neg //defining class Neg

{  

public static void replaceEvens(int[] numbers) //defining a method replaceEvens that accepts array

{

int i; //defining integer variable

for(i = 0 ; i < numbers.length; i++) //defining foop to counts number

{

if(numbers[i]%2 == 0) //defining condition to check number is even  

{

numbers[i] = numbers[i] * -1; //multiply the number by -1

}

}

for(i = 0 ; i < numbers.length; i++) // defining loop print array

{

System.out.print(numbers[i] + " "); //print array

}

}    

public static void main(String[] as)//defining main method  

{

   int[] numbers = {12, 10, 18, 5, 2,22}; //defining array numbers and assign value

   System.out.println("Elements of array: "); //print message

   for(int i = 0 ; i < numbers.length ; i++)  //defining loop to print message

   {

   System.out.print(numbers[i] + " "); //print array

   }

  System.out.println("\n After replaceEvens"); //print message

   replaceEvens(numbers); //calling method replaceEvens

  }

}

Output:

please find the attachment.

Explanation:

  • In the given program a static method replaceEvens is declared, in which array numbers pass as the parameter, inside the for method loop is declared, which counts array number in this loop if block is defined, that check-in array there is an even number.
  • In the condition is true it will multiply the number by -1, and output side the loop it will define another loop to print its value.
  • Inside the main method, a number array is declared, that first prints its value then call the method to print its change value.    

3 0
3 years ago
Justine was interested in learning how to play the piano. Before she was allowed to even play the piano, she has had to learn
Setler [38]

Answer:

A

Explanation:

The answer is A because, to be novice at something that means one is new to and is inexperienced at said activity.

3 0
3 years ago
Read 2 more answers
What will you see on the next line? &gt;&gt;&gt; int(6.5)
tankabanditka [31]

Answer:

6

Explanation:

The int functions founds down to the nearest whole number, which in this case would be 6.

8 0
2 years ago
Read 2 more answers
Jack is writing a paragraph for a school assignment. He proofreads his paper and notices that he used the word, "then" many time
Lynna [10]

He should use a Thesaurus.

5 0
3 years ago
Read 2 more answers
In a non-price rationing system, consumers receive goods and services first-come, first served. Give me an example of a time whe
Anna35 [415]

When someone may be giving away something for free.

7 0
2 years ago
Other questions:
  • Food is shipped thousands of miles throughout our country using various types of transportation such as trucks, planes, and boat
    10·1 answer
  • Which loan type requires you to make loan payments while you’re attending school?
    7·1 answer
  • What is the single most important component of a computer? Central Processing Unit DIP Motherboard Chipset
    8·1 answer
  • How can you ensure you don't go over your budget?
    8·1 answer
  • Which type of server runs Active Directory?
    12·1 answer
  • Write a function in Java that implements the following logic: Given a string and an int n, return a string made of n repetitions
    15·1 answer
  • A binary message consisting of four bits was sent to you by a friend. The message was supposed to be ABAB. Unfortunately, your f
    8·1 answer
  • High level language - An object oriented programming language​
    5·1 answer
  • Write the line of code to calculate the area of a circle with radius 3 and store it in a variable called
    10·1 answer
  • What might a designer need to consider when choosing an appropriate energy source for products and power systems
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!