Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Consider the following statements that are contained in main int [JJinStock s

ID: 3587130 • Letter: 1

Question

1. Consider the following statements that are contained in main int [JJinStock s new int [10[4] int [J alpha new int [20] int [ ] beta = new int [20]. int [ J gama (11, 13, 15, 17) int [ ] delta (3,5, 2,6, 10, 9,7, 11, 1, 8: a. Write the definition of the method inputArray that prompts the user to input 20 numbers and stores the numbers in alpha. b. Write the definition of the method doubleArray that initializes the elements of beta to 2 times the corresponding elements in alpha. Make sure that you prevent the method from modifying the elements of alpha c. Write the definition of the method copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to 3 times the previous row of inStock. Make sure that you prevent the d. Write the definition of the method copyAlphaBeta that stores alpha into Make sure that you prevent the method from modifying the elements of method from modifying the elements of gamma the first 5 rows of inStock and beta into the last 5 rows of inStock alpha and beta. dimensional array of the type int. Print 15 elements per line. e. Write the definition of the method printArray that prints any one- f. Write the definition of the method setInStock that prompts the user to input the elements for the first column of inStock. The method should then set the elements in the remaining columns to 2 times the corresponding element in the previous column, minus the corresponding element in delta. Write a complete Java program that tests the method main and all of the methods discussed in parts a through f. Remember to write Java statements that call each of the methods and format the output. Use the following input for 20 integers 12345678912345678912

Explanation / Answer

import java.util.ArrayList;

import java.util.Scanner;

public class Array {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner s=new Scanner(System.in);

//initialise all the array

int [][]stack=new int[10][4];

int[]alpha=new int[20];

int[]beta=new int[20];

int[]gamma={11,13,15,17};

int[]delta={3,5,2,6,10,9,7,11,1,8};

//for a(input array) will use for loop and ask the user to enter 20 inputs.

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

{

alpha[i]=s.nextInt();//statement for input the data or copy the input and store it to alpha array.

}

b)double array

//double the size of alpha and copy the elements of beta to alpha

int[]new alpha=new int[2*size of alpha];

for(inti i=0;i<20;i++)

{beta[i]=s.nextInt();//take the input from user;

alpha[i]=beta[i];//copy the elements from beta to alpha

alpha[i+20]=beta[i]//stores the first element of beta in 21st possition so that previous alpha won't change.

}

c)copy gamma

int[][]instack=new int[10[[4];//10 rows 4 coloums 2 D Array

//initialise instack

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

{for(int j=0;j<4;j++)

{instack[i][j]=s.nextInt();//take the input from user

//now copy the data of gamma to 1st row

}

}

//copying data for first row of instack

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

{instack[1][i]=gamma[i];//this statement will copy the data of gama to instack

}

//making others rows to 3time the previous rows

int[][]instack=new int[3*size of instack][4];

d)copy alpha beta

//for alpha(first 5 rows of instack)

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

{for(int j=0;j<4;j++)

{instack[i][j]=alpha[i];

}

//for beta(last 5 rows of instack)

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

{for(int j=0;j<4;j++)

instack[i+5]=beta[i];

}

e)

//for print

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

{for(int j=0;j<4;j++)

{system.out.println(instack[i][j]);

}

}

}