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
Fortnite anyone? i just started tdy so dont be judgiee lol
algol [13]
I used to play fortnite but i don’t now
6 0
3 years ago
Read 2 more answers
what tool can a student use to make sure his or her work paper does not take credit for someone else's work ?
AlekseyPX

You can use a plagiarism checker.

8 0
3 years ago
Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi
Harlamova29_29 [7]

Answer:

The removeTens method is as follows

public static int[] removeTen(int[] nums) {

int [] arr = nums;

   int index = 0;

   while(index < arr.length && arr[index] != 10){

       index++;

   for(int j = index + 1; j < arr.length; j++) {

       if(arr[j] != 10) {

           arr[index] = arr[j];

           arr[j] = 10;

           index++;        }    }

   for( ; index < arr.length; index++){

       arr[index] = 0;}}

   return arr;

}

Explanation:

This defines the removeTens method; it receives array nums as its parameter

public static int[] removeTen(int[] nums) {

This creates and initializes a new array

int [] arr = nums;

This initializes index to 0

   int index = 0;

The following is repeated when array element is not 10 and if array index is still valid

   while(index < arr.length && arr[index] != 10){

This increments the index by 1

       index++;

This iterates through the array

   for(int j = index + 1; j < arr.length; j++) {

This checks if array element is not 10

       if(arr[j] != 10) {

If yes:

           arr[index] = arr[j];

The current array element is set to 10

           arr[j] = 10;

The index is incremented by 1        

  index++;        }    }

This iterates through the array again and move 0s to the back

   for( ; index < arr.length; index++){

       arr[index] = 0;}}

This returns the new array

  return arr;

}

8 0
3 years ago
Now tell me how be rich like Bill Gates
Lunna [17]
Get a good education and a good job and stay focused in life
5 0
3 years ago
What are 6 subtopics on computer programming ?
lubasha [3.4K]

On the internet, I found

Research topics

Artificial Intelligence

Computing and Mathematics

Cybersecurity

Data Science and Machine Learning

Embedded Systems and IoT

Process Management

Hope this helped :T

3 0
3 years ago
Other questions:
  • Write a program that takes two ints as input from the keyboard, representing the number of hits and the number of at bats for a
    10·1 answer
  • Assume that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 month
    13·1 answer
  • Microprocessors can’t directly understand programming languages, so programs have to be converted into _____________ that corres
    15·1 answer
  • How is actual cost calculated?<br><br> Please answer
    12·1 answer
  • . A wireless ……..is a device used to resolvewireless network connectivity problems.
    8·1 answer
  • The camera still is bad even with the new iPhone xr and especially in low light it is even worst because you can see the pixels
    15·1 answer
  • Why must you be careful when handling a hard drive?
    10·1 answer
  • Convert the decimal integer, 353.87510 to each of these forms:
    9·1 answer
  • Calculate the total and average number from 1 to 100<br>​
    12·1 answer
  • Question 7 (1 point)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!