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
(15 POINTS) When an error is made in HTML code, the browser does what?
Rzqust [24]
Look up "List of HTTP status codes" in Wikipedia. It's important to know the error and this list show what possibilities exist.
7 0
3 years ago
Higher Order Functions used for simulations of dice rolls. Definition: An n-sided dice function takes no arguments and always re
tiny-mole [99]

Answer:

#include <iostream>

#include <time.h>

#include <string>

using namespace std;

int main(){

srand(time(NULL));

cout<<"Throw dice"<<endl;

int b =0;

int a=0;

a=rand()%6;

b=rand()%6;

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

{cout<<"dice one: "<<a<<endl;}

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

{cout<<"dice two: "<<b<<endl;}

if(a>b)

{cout<<"first dice won"<<endl;}

if(b>a)

{cout<<"second dice won"<<endl;}

else{cout<<"they are same"<<endl;

return main();

}

return 0;

}

Explanation:

/*best dice roll game just for you change it as you want but all necessary things are there/*

5 0
2 years ago
Why does my laptop keep disconnecting from the wifi.
poizon [28]

Answer: you may be connected to wifi near you

Explanation:

1. Restart your computer

2 Then got to settings

3 Go to Wi-Fi

4. Disconnect from your Wi-Fi

5 Connect to your Wi-Fi

If that does not work, go look it up lol.

3 0
2 years ago
For each of the following application areas state whether or not the tree data structure appears to be a good fit for use as a s
Cerrena [4.2K]

Answer:

a) Chess game moves:- Tree data structure is not a good fit.

b) Public transportation paths:- Tree data structure is not a good fit.

c) Relationshi[p among computer files and folders:- Tree data structure is a good fit.

d) Genealogical information:- Tree data structure is a good fit.

e) Parts of books:- Tree data structure is a good fit.

f) Programming language history:- Tree data structure is not a good fit.

g) Mathematical expression:- Tree data structure is a good fit.

Explanation:

a) Chess game moves:- Tree data structure is not a good fit. Since in tree data structure moving backward or sharing the node is not that much easy. Presume, In chess, you have to check any box is empty or not. Here, Graph is the best fit.

b) Public transportation paths:- Tree data structure is not a good fit. whenever shortest path, routes, broadcast come always graph is a good option. Because in the tree you don't know how many time you visit that node

c) Relationshi[p among computer files and folders:- Tree data structure is a good fit. Since they have a predefined route. Go to 'c' drive. Open a particular folder and open a particular file.

d) Genealogical information:- Tree data structure is a good fit. Since genealogical information also has a predefined route. Here, the Graph is not suitable.

e) Parts of books:- Tree data structure is a good fit. Since manages the chapters and topics are not that much complex. You can see any book index which is in a very pretty format.

f) Programming language history:- Tree data structure is not a good fit. To store the history of the programming language we need some unconditional jumps that's why the tree is not suitable.

g) Mathematical expression:- Tree data structure is a good fit. The tree is suitable in some cases. We have an expression tree for postfix, prefix.

5 0
3 years ago
HELP ME PLEASE
seraphim [82]

Answer:

Questions and answers

Explanation:

3 0
2 years ago
Other questions:
  • In three to five sentences, explain how you would insert graphics using your word-processing software.
    7·2 answers
  • When pasting information copied from a Word document into an Excel spreadsheet, click in the cell that will be the _______ of th
    7·2 answers
  • Which feature is an interface between the user and the file system of a computer?
    6·2 answers
  • Which of the following is true of standard error? a. It can take negative values. b. It is an estimate of the standard deviation
    6·1 answer
  • Write a program name Dollars that calculates and displays the conversion of an entered number of dollars into currency denominat
    11·1 answer
  • HURRY!!!!!!!!!!!!!
    15·1 answer
  • A production house needs an operating system that captures saves and generates information within a specific time. Which type of
    11·1 answer
  • Does digital media play a big role in your life?
    13·1 answer
  • Using existing algorithms as building blocks for new algorithms has all the following benefits EXCEPT
    12·1 answer
  • Write a static method reOrder56(int[] nums) that return an array that contains exactly the same numbers as the given array, but
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!