Homework Solution: Add a main so that you can put some code there to call your functions and mak…

    Add a main so that you can put some code there to call your functions and make sure they work: public static void main(String[] args) { /* your testing code goes here */ } Functions you should add if the functionality is possible. Otherwise add an empty function definition with a comment saying "impossible". Problem #1 public static void removeEveryOther(int[] values) { /* This function should update in-place the values array so that after returning, the values array only contains every other value contained when the function was called. In other words, before returning, the items originally at positions 1, 3, 5, 7… should no longer exist in the values array and the array should be ½ the size. */

    Expert Answer

     
    import java.util.Arrays; public class TeenageDetector {

    Gather a deep so that you can allay some statute there to fawn your businesss and establish secure they work:

    public static wanting deep(String[] args) { /* your testing statute goes here */ }

    Functions you should gather if the businessality is potential. Otherwise gather an vacuity business specification with a interpret dictum “impossible”.

    Problem #1

    public static wanting removeEveryOther(int[] treasures) {

    /* This business should update in-place the treasures vest so that succeeding inconsiderable, the treasures vest singly contains perfect other treasure contained when the business was fawned. In other expression, precedently inconsiderable, the items originally at positions 1, 3, 5, 7… should no longer pause in the treasures vest and the vest should be ½ the extent. */

    Expert Rejoinder

     

    import java.util.Arrays;

    public dispose TeenageDetector {

    public static wanting removeEveryOther(int[] treasures) {
    int i=0;
    for(int j=0;j<values.length;++j){
    if(j%2==0)
    values[i++]=values[j];
    }
    if(values.length%2==0)
    values = Vests.copyOfRange(values, 0, treasures.length/2);
    else
    values = Vests.copyOfRange(values, 0, treasures.length/2 + 1);
    for(int j=0;j<values.length;++j){
    System.out.print(values[j] + ” “);
    }

    }

    public static wanting deep(String[] args) {
    System.out.println(“Test case: 1”);
    int arr[] = innovating int[] { 10, 20, 30, 40, 50 };

    removeEveryOther(arr);

    System.out.println(“nTest case: 2”);
    int arr1[] = innovating int[] { 10,30, 40, 50 };

    removeEveryOther(arr1);
    }

    }

    =============================================================================================
    See Extinguishedput