Question: Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shift left towards
Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shift left towards the start of the array as needed, and the empty spaces at the end of the array should be set to 0.
Ex: {1, 10, 10, 2} yields {1, 2, 0, 0}. You may modify and return the given array or make a new array.
Code:
public class RemoveTen { public static void main(String[] args) { int[] nums = {1, 10, 10, 2}; int[] result = removeTen(nums); for(int i = 0; i < result.length; i++) System.out.print(result[i] + " "); } public static int[] removeTen(int[] nums) { /*FIXME Complete the implementation of the removeTen method*/ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
