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
Entering the formula =sum(c5:c18) in cell c19 will result in which of the following?
antiseptic1488 [7]
If you mean Excel formula sum(c5:c18) in cell c19 will show <span>c. the total of cells c5 to c18 will appear in cell c19. It's simple operation that simplyfies counting different values.</span>
5 0
3 years ago
Write a program that applies the Euclidean algorithm to find the greatest common divisor of two integers. Input should be two in
laila [671]

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// function that return greatest common divisor

int g_c_d(int num1, int num2)

{

if (num1 == 0)

 return num2;

return g_c_d(num2 % num1, num1);

}

// main function

int main()

{

// variables

int num1,num2;

cout<<"enter two numbers:";

// read two numbers from user

cin>>num1>>num2;

// call the function and print the gcd of both

cout<<"greatest common divisor of "<<num1<<" and "<<num2<<" is "<<g_c_d(num1.num2)<<endl;

}

Explanation:

Read two numbers from user and assign them to variables "num1" and "num2".Call the function g_c_d() with parameter "num1" and "num2".According to Euclidean algorithm, if we subtract smaller number from the larger one the gcd will not change.Keep subtracting the smaller one then we find the gcd of both the numbers.So the function g_c_d() will return the gcd of both the numbers.

Output:

enter two numbers:5 9

greatest common divisor of 5 and 9 is 1

enter two numbers:-25 15

greatest common divisor of -25 and 15 is 5

6 0
4 years ago
Which of these statements are true of verifying that a program’s code is fixed? Check all of the boxes that apply.
aksik [14]

Answer:

Its C.

Explanation:

hope it helps !

mark me brainliest :))

7 0
3 years ago
Read 2 more answers
A task-oriented leader is ideal for a creative workplace.
klio [65]
CORRECT ANSWER:
True
8 0
3 years ago
Read 2 more answers
Robin has four copies of her midterm paper saved to a single folder on her
Mumz [18]

Answer:

i think its b

Explanation:

im not sure but b seems reasonable. sorry if you get it incorrect :(

6 0
3 years ago
Other questions:
  • You have been tasked with finding the routers that have been installed between two networks. what utility would you use to provi
    5·1 answer
  • . What are the typical parts of a Change Request Document?
    6·1 answer
  • What can you search on Microsoft Word or Powerpoint Clipart or Google (Clip art) to find more pictures like the ones below but w
    7·1 answer
  • Gabriel needs to create a formula that does not change when it is copied to cell b2. which formula should he create?
    14·1 answer
  • When users talk about font size,
    10·2 answers
  • Suppose we want to design a combinational logic block that accepts a 4 bit Binary number as input. Let the most significant bit(
    14·1 answer
  • When entering numbers that start with a zero, apply the _____ number format.
    12·1 answer
  • Can you adopt me in the orphanage u saw Tammy after school?
    7·1 answer
  • How do i get around a school related block
    13·2 answers
  • which one of the following would not normally be found in an organization's information security policy?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!