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]
4 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]4 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
You want to transfer a document from one computer to another, and you want the document to be encrypted. The destination compute
Alex_Xolod [135]

Answer:

Check the explanation

Explanation:

This document transfer ought to work smoothly. Due to the IEEE standards and Principles, the presentation layer is expected to encrypt/decrypt the data on both part of the network. The session layer creates a mutual coordination among the applications while the transport layer is there to ensures delivery. Immediately the segments hit the network, routers control and handle the routing process of the packets to the distant end. Layers 6, 3 & 1 are straightly involved in the italicized parts of the question; however, the entire layers play a role when looking at the transfer as a whole.

5 0
3 years ago
Write a program that accepts a file name from the command line, then initializes an array with test data using that text file as
postnew [5]

Answer:

Complete code is given below:

Explanation:

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.Arrays;

import java.util.Scanner;

public class ArrayCalcs {

private int size;

String [] parts =null;

// based on number of elements in file, array will create.

double[] arr=null;

public void readFile(String file){

try{

FileReader fr = new FileReader(file+".txt");

BufferedReader br = new BufferedReader(fr);

String line = br.readLine();

int count = 0;

while (line != null) {

parts = line.split(" ");

for( String w : parts)

{

count++;

}

line = br.readLine();

}

size=count;

arr=new double[size];

for(int i=0;i<size;i++){

arr[i]=Double.parseDouble(parts[i]);

}

// System.out.println(count);

// System.out.println(Arrays.toString(parts));

System.out.println(Arrays.toString(arr));

} catch (FileNotFoundException ex){

System.out.println("This file does not exist");

} catch (IndexOutOfBoundsException e){

System.out.println("Thie file has more than 7 lines");}

catch (IOException e) {

System.out.println(e.getMessage());

}

}

public double getTotal(){

double sum=0.0;

for(double d:arr){

sum=sum+d;

}

return sum;

}

public double getAverage(){

double avg=getTotal()/arr.length;

return avg;

}

public double getHighest(){

double high=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] > high)

high = arr[i];

}

return high;

}

public double getLowest(){

double low=arr[0];

for(int i=0;i<arr.length-1;i++){

if(arr[i] < low)

low= arr[i];

}

return low;

}

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter file name:");

String file=s.next();

ArrayCalcs ac=new ArrayCalcs();

ac.readFile(file);

System.out.println(" Highest Element: "+ac.getHighest());

System.out.println("Lowest Element: "+ac.getLowest());

System.out.println("Total: "+ac.getTotal());

System.out.println("Average: "+ac.getAverage());

}

}

4 0
3 years ago
the piece of hardware that contains the circuitry that processes the information coming in to the computer and tells the other h
vagabundo [1.1K]

that sound like the CPU, the central processing unit, it handles the informations and distributes it.

7 0
3 years ago
Samantha wants to begin searching for a job using the Web. The best source for her online search will probably be __________.
zalisa [80]

Answer:

C) A company's website

Explanation:

8 0
2 years ago
What is the capacity of a disk with two platters, 10,000 cylinders, an average of 400 sectors per track, and 512 bytes per secto
natita [175]

Answer:

The capacity of the disk is "40 GB".

Explanation:

Given value:

\to \text{cylinder}= 10,000\\\\\to \frac{sector}{track} = 400\\\\\to \frac{bytes}{sector} = 512\\

\text{Calculating the size of track} =  \frac{bytes}{sector} \times  \frac{sector}{track}

                                            = 512 \times  400 \\\\ = 204,800 \ \ Or  \ \ 200 \ K

\text{Calculating the size of surface} = \frac{byte}{track} \times \ cylinder

                                               = 2000 \ K \times  10,000 \\\\ = 20, 000,000 \ K

\text{Calculating the capacity of a disk} = \frac{byte}{surface} \times \frac{surface}{disk}

                                                     = 20, 000,000 \ K \times  2 \\\\ = 40, 000,000 \ K \\\\= 40 \ GB

Cache memory is often used to speed up the runtime. It will enable us to improve performance unless we can store information, that is retrieved constantly in memory space.

  • Hit Cache: when the Processor relates to representing database data, Cache Hit results.
  • Miss Cache: when this Processor responds to a non-present cache data, this will trigger its miss of cache.
  • It doesn't have to retrieve the Main Memory through secondary storage.
3 0
3 years ago
Other questions:
  • A search engine displays a list of webpage names that contain the search text. what is the term for that list?
    14·1 answer
  • A company ABC asked you to design a simple payroll program that calculates and employee's weekly gross pay, including any overti
    9·1 answer
  • Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single
    11·1 answer
  • What are the benefits of using disk cleanup as part of regular maintenance on a computer​
    8·1 answer
  • What is the rationale behind the development of an operating system in computing?
    15·1 answer
  • Cliff just started working with a client who has a very disorganized AdWords account. What’s an effective way for him to begin r
    15·1 answer
  • A(n) ________________ must be completed immediately following an incident as it is an essential document that details an inciden
    14·1 answer
  • Weird canvas submission, I’ve done directly what the directions say to do to submit it, but it won’t submit
    15·1 answer
  • What color and hat do you choose in Among Us
    15·1 answer
  • In what ways can you modify the location of the neutral point?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!