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
Tems11 [23]
3 years ago
5

Given an integer n and an array a of length n, your task is to apply the following mutation to an: Array a mutates into a new ar

ray b of length n.
For each i from 0 to n - 1, b[i] = a[i - 1] + a[i] + a[i + 1].
If some element in the sum a[i - 1] + a[i] + a[i + 1] does not exist, it should be set to 0. For example, b[0] should be equal to 0 + a[0] + a[1].
Computers and Technology
1 answer:
Elenna [48]3 years ago
3 0

Answer: provided in the explanation section

Explanation:

import java.util.*;

class Mutation {

public static int[] mutateTheArray(int n , int[] a)

{

int []b = new int[n];

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

{

b[i]=0;

if(((i-1)>=0)&&((i-1)<n))

b[i]+=a[i-1];

if(((i)>=0)&&((i)<n))

b[i]+=a[i];

if(((i+1)>=0)&&((i+1)<n))

b[i]+=a[i+1];

}

return b;

}

  public static void main (String[] args) {

      Scanner sc = new Scanner(System.in);

      int n= sc.nextInt();

      int []a = new int [n];

     

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

      a[i]=sc.nextInt();

     

      int []b = mutateTheArray(n,a);

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

      System.out.print(b[i]+" ");

     

 

     

  }

}

cheers i hope this helped !!

You might be interested in
The while loop is also known as what kind of a loop? entry-control loop operational loop infinite loop user-control loop
Alexxx [7]
Entry control loop. Because a while loop can be infinite or not based on whether Boolean given is T or F. So we need to know the preexisting condition before we can solve it.
7 0
1 year ago
NO SPAMMERS, ONLY FULL ANSWER
melisa1 [442]

Answer:

true

Explanation:

4 0
2 years ago
Read 2 more answers
BOTH QUESTIONS ONLY FILL IN C++ CODEWrite a copy constructor for CarCounter that assigns origCarCounter.carCount to the construc
Alborosie

Answer:

im lost tell me a question then ill answer

Explanation:

4 0
3 years ago
As a compositional mode for electronic? media, __________ help people find their way through an unfamiliar system or? subject; t
maks197457 [2]
The answer that fills in the blank is orientation. It is because orientation does not provide all the details of what they are doing but a guideline of what they must do, in order for them to be guided on the things that they need to learn as they start. They require proper guidance which is the orientation before performing before hand. Especially when they are not familiar on what they need to do.
3 0
3 years ago
A merge is _____.
Aliun [14]
The process of combining information from a variety of sources
7 0
3 years ago
Read 2 more answers
Other questions:
  • Steve wants to become a successful graphic design entrepreneur. Which entrepreneurial approach will help him succeed? A. working
    14·1 answer
  • Is there truth? Does truth exists?
    14·2 answers
  • You may nest while and do-while loops, but you may not nest for loops<br><br><br><br> True False
    10·1 answer
  • An element in an array is 4 bytes long and there are 10 elements in the array. How big is the array?
    6·2 answers
  • What is the fastest way to move data over long distances using the internet, for instance across countries or continents to your
    13·1 answer
  • Analyze the following code. Which of the following statements is correct?
    9·1 answer
  • In your own words, describe how a network administrator can use the OSI model to isolate a network problem.
    13·1 answer
  • Witch factor will increase a populations size
    6·2 answers
  • Complete each sentence using the drop-down menu. Information on local driving laws can be found on a website. A class textbook c
    9·2 answers
  • What is the positional weigh of the digit 7 in the octal number 7642 ?​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!