Question: Writing a method called remove(int index) -> remove the obj at position = index->move elements to the left and put a zero at the end

Writing a method called remove(int index) -> remove the obj at position = index->move elements to the left and put a zero at the end

CODE:

package MyArrayListInvestigation;

public class MyArrayListProg2B { public static int remove(int pos, int[]a) { //remove the element at pos //return the element that was removed //in most move the data inward and replace the end with a 0 return 0; } public static void printArray(int []array) { //print horizontally } public static void main(String[] args) { // TODO Auto-generated method stub int pos =2; int[]array1= {10,20,30,30,40,50};//result {10,20,30,40,50,0} remove(pos,array1); printArray(array1); pos =0; int[]array2= {10,10,20,30,40,50};//result {10,20,30,40,50,0} remove(pos,array2); printArray(array2); pos =5; int[]array3= {10,20,30,40,50,55};//result {10,20,30,40,50,0} remove(pos,array3); printArray(array3); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!