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
astraxan [27]
4 years ago
9

Given an integer n and an array a of length n, your task is to apply the following mutation to a:

Computers and Technology
1 answer:
jok3333 [9.3K]4 years ago
5 0

Answer:

The program written in Java is as follows

import java.util.Scanner;

public class mutilate {

public static void main(String [] args) {

Scanner input = new Scanner(System.in);

int n;

System.out.print("Array Length: ");

n = input.nextInt();

while(n<1 || n > 103)  {

    System.out.print("Array Length: ");

n = input.nextInt();

}

int a []= new int [n];

int b []= new int [n];

System.out.print("Enter Elements of the Array: ");

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

 a[i] = input.nextInt();

}

System.out.print("Output: ");

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

 if(i == 0)   {

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

 }

 else if(i == n-1)   {

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

 }

 else   {

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

 }

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

}

}

}

Explanation:

This line allows the program accepts user input

Scanner input = new Scanner(System.in);

This line declares integer n

int n;

The next two line prompts user for length of the array and also accepts input

<em> System.out.print("Array Length: "); </em>

<em> n = input.nextInt(); </em>

The following while iteration ensures that the user input is between 1 and 103

<em> while(n<1 || n > 103)  { </em>

<em>     System.out.print("Array Length: "); </em>

<em> n = input.nextInt(); </em>

<em> } </em>

The next two lines declares array a and b

<em> int a []= new int [n]; </em>

<em> int b []= new int [n]; </em>

The next for iteration allows user enter values for array a

System.out.print("Enter Elements of the Array: ");

<em> for(int i =0;i<n;i++)  { </em>

<em>  a[i] = input.nextInt(); </em>

<em> } </em>

The next for iteration calculates and prints the values for array b based on the instruction in the question

<em> System.out.print("Output: "); </em>

<em> for(int i =0;i<n;i++)  { </em>

<em>  if(i == 0)   { </em>

<em>      b[i] = 0+a[i]+a[i+1]; </em>

<em>  } </em>

<em>  else if(i == n-1)   { </em>

<em>      b[i] = a[i - 1]+a[i]+0; </em>

<em>  } </em>

<em>  else   { </em>

<em>  b[i] = a[i - 1]+a[i]+a[i+1];     </em>

<em>  } </em>

<em>  System.out.print(b[i]+" "); </em>

<em> } </em>

Download java
You might be interested in
Item 3Item 3 John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastruc
White raven [17]

Answer:

Replacing computer parts.

Explanation:

John replaces faulty computer parts, such as DVDs, hard drives, ram cards, wires etc. John can also replace the whole motherboard or clean it (for dust).

Computer parts not functioning properly or dying is a common problem in computer systems. Motherboard, the circuit that holds all the components of a computer, like CPU, Ram and Hard disk, can also fail or die.

5 0
3 years ago
Paul is playing a game when his computer shuts down unexpectedly. Paul has noticed recently that his fans are running very loud.
Elis [28]

Answer:

there is a lot of heat in his computer he should let the computer rest for some time and then use it again

5 0
4 years ago
Are there any Free programs that let's you use the GreenScrene? But, inside already made videos not while making the video.
Trava [24]
The programs I know that let you use the GreenScreen on already made videos is imovie and SonyVegas Pro. I know how hard it is to find friendly opinions from others so they can help you when trying to find Edit related programs for pictures and videos. I hope this helped.   
5 0
3 years ago
How does computer applications affect our lives daily? 1- paragraph (4 sentences)
Mnenie [13.5K]

Answer:

Computers affect our lives daily because we use them everyday to browse the internet and solve problems in real life. They help solve problems and without them, getting certain information would be much harder. They help us interact with friends from anywhere in the world and communicate with relatives. It has also helped us during this pandemic and lets us learn from school in the safety of our own home.

( hope this helps, i wrote it myself ;-; )

4 0
3 years ago
Read 2 more answers
Ok- well uhm- I need someone's opinion again :')<br> Which one looks better 0.0
Kryger [21]

Answer:

They both look really good but i think the white looks better

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • How does a saffir put out fires
    12·1 answer
  • A web ______ is a computer that delivers requested webpages to your computer or mobile device.
    7·1 answer
  • The replacer parameter of the stringify method accepts a/an ______________ or an array.
    15·1 answer
  • 1. when is it a good idea to use lossless compression
    8·1 answer
  • How does Wireshark differ from NetWitness Investigator?
    6·1 answer
  • Suppose you are purchasing something online on the Internet. At the website, you get a 10% discount if you are a member. Additio
    12·1 answer
  • What is the range for copper tape
    15·1 answer
  • Edhesive 6.2
    6·2 answers
  • Please answer this question​
    13·1 answer
  • Evaluate how suitable the hardware would be for:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!