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
What is the binary for O?​
nevsk [136]

Answer:

01001111

Explanation:

8 0
2 years ago
Read 2 more answers
8.3 code practice edhesive PLEASE HELP AND HURRY
NemiM [27]

Answer:

numbers = '14 36 31 -2 11 -6'

nums = numbers.split(' ')

for i in range(0, len(nums)):

  nums[i] = int(nums[i])

print(nums)

8 0
3 years ago
Sidney works in the accounting department. His boss just assigned him a task that involves creating budget formulas for the comp
madreJ [45]
In excel spreadsheets, Sidney need to consider specifying relationships between the information you have stored in your spreadsheets when creating formulas. The elements that will help you understand using spreadsheet are the constants, operators, references and functions. This will enable her to use the formulas, without hassle in spreadsheets.
6 0
3 years ago
Gustavo is completing his homework online. When he uses a computer, what converts the information he inputs into instructions th
Otrada [13]
I can not understand your question, about it. What is homework of Gustavo working in, Visual or Dev C++ with any language?
4 0
3 years ago
Read 2 more answers
Anyone have the Dell xps 13 laptop? if not pls don't answer but if you do, how is it going for you?​
Nady [450]

I do and it’s going alright; would recommend. Here’s what I think in bullet points.

- Good aesthetic design. Weave-like texture is nice and somewhat opulent.

- Good performance; you can overclock the i7 CPU.

- Battery life is at the upper end of the spectrum.

- No USB Type A Ports, big downside.

- Graphics are about 1000 points above industry average (3D Mark Fire Spark)

- Uses an SSD rather than a HDD; much quicker load time.

- I’d go for the $1,899 personally; it’s worth the extra money.

Thanks.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following matching is true concerning the Protocol Data Unit (PDU) and its corresponding OSI layer location?
    15·1 answer
  • Which of the following would be an example of a loss of record integrity in a
    12·1 answer
  • Turning up the transmit power or utilizing a high gain antenna to reach wireless users from a distance increases your exposure t
    12·1 answer
  • There are a few simple rules that you can follow to store and manage files and folders in your computer. What is the most import
    9·2 answers
  • Difference between ancient and modern mode of information <br> transmission
    12·1 answer
  • In cell n2, enter a formula using the if function and a structured reference to determine if allison simoneau is eligible for tu
    11·1 answer
  • Jabria are you smart
    14·2 answers
  • The internet in this Packet Tracer network is overly simplified and does not represent the structure and form of the real intern
    11·1 answer
  • Consider the conditions and intentions behind the creation of the internet—that it was initially created as a tool for academics
    12·1 answer
  • You are an IT administrator troubleshooting a Windows-based computer. After a while, you determine that you need to refresh the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!