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
Which is true about a computerized spreadsheet?
morpeh [17]
"A computerized spreadsheet automatically recalculates when changes are made to the data" is the one among the following that <span>is true about a computerized spreadsheet. The correct option among all the options that are given in the question is the third option or option "C". I hope it helps you.</span>
5 0
3 years ago
Javascript is an object-based programming language that involves working with the properties and methods associated with objects
dimulka [17.4K]

Answer:

True

Explanation:

You can set variables and make method functions.

4 0
2 years ago
Consider the following statements. An abstract class is better than an interface when the variables in the abstract class or int
Ksivusya [100]
Well the nonchalant question given for 4th grade red named babyface Justin and Jerome
4 0
2 years ago
Who is the father of computer​
Irina-Kira [14]

Answer:

Charles babbage is the father of computer

5 0
3 years ago
Between which zones and a DMZ should firewalls be placed? Choose two answers.
brilliants [131]

Answer:

Internal and External Zones

Explanation:

Demilitarized Zone (DMZ) in a network means that, we make sure the security of network at higher level as military make sure the security of their bases or zones.

In this type of network, The network of the internal organization (LAN) needs security from hackers and unauthorized users who are trying to access the resources and information from the network.

This network is divided into two major zones. A DMZ has been placed between two zones along with firewalls enhance the security of LAN Network from the networks on internet. These two zones are named as Internal and External Zone. The firewall between DMZ and External zones monitors the users from external networks on the internet who tries to access organization's network. Internal network monitors the traffic between DMZ and Internal LAN network.

4 0
3 years ago
Other questions:
  • Which wildcat character will return a single character when using the find dialog box
    14·1 answer
  • What does Intel mean in this phrase(collect all intel).
    9·2 answers
  • What is the most flexible way to modify a report?
    7·1 answer
  • The title of a Web page is the text that appears on the title bar and taskbar of the browser window. *
    13·1 answer
  • The Speed of Sound (Java Project. Please make it easy to understand. I'm a beginner at this. I believe we are supposed to use a
    5·1 answer
  • Machines may aid in making work easier over a longer distance. true or false.
    7·1 answer
  • Relation between training and occupation with examples in points . Plz tell fast<br> ​
    5·1 answer
  • Where ....................... the books that you borrowed? *
    5·1 answer
  • 1. Do our shared social experiences lead us to think<br><br> communication is a cure-all?
    13·1 answer
  • How do you put text in MS publisher?<br><br> When do you use text wrapping?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!