Question
public class HW4 { public static void main(String[] args) { //Array int[] a = {2,8,5,4,6}; System.out.println(---------------------); System.out.println(Initial Array); print(a); System.out.println(---------------------); System.out.println(Update Array: Change value in
public class HW4 { public static void main(String[] args) { //Array int[] a = {2,8,5,4,6}; System.out.println("---------------------"); System.out.println("Initial Array"); print(a); System.out.println("---------------------"); System.out.println("Update Array: Change value in index 2 to 7"); a = update(a, 2, 7); //Change value in index 2 changes from 5 to 7 print(a); System.out.println("---------------------"); System.out.println("Add value 3 to the end of the array"); a = add(a,3); //Add value 3 to the end of the array print(a); System.out.println("---------------------"); System.out.println("Insert value 9 into index 3"); a = insert(a,3,9); //Insert value 9 into index 3 print(a); System.out.println("---------------------"); System.out.println("Delete the value in index 3"); a = delete(a,3); //Delete the value in index 3 print(a); }
public static int[] update(int[] array, int index, int value) { array[index] = value; return array; }
public static int[] add(int[] array, int value) { int[] temp = new int[array.length+1]; for (int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started