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 {

    Subjoin a deep so that you can spread some edict there to ole your discharges and reach safe they work:

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

    Functions you should subjoin if the dischargeality is likely. Otherwise subjoin an leisure discharge restriction with a note saw “impossible”.

    Problem #1

    public static bereft removeEveryOther(int[] estimates) {

    /* This discharge should update in-place the estimates marshal so that behind inconsiderable, the estimates marshal barely contains integral other estimate contained when the discharge was oleed. In other articulation, precedently inconsiderable, the items originally at positions 1, 3, 5, 7… should no longer stop in the estimates marshal and the marshal should be ½ the bulk. */

    Expert Rejoinder

     

    import java.util.Arrays;

    public arrange TeenageDetector {

    public static bereft removeEveryOther(int[] estimates) {
    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 = Marshals.copyOfRange(values, 0, estimates.length/2);
    else
    values = Marshals.copyOfRange(values, 0, estimates.length/2 + 1);
    for(int j=0;j<values.length;++j){
    System.out.print(values[j] + ” “);
    }

    }

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

    removeEveryOther(arr);

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

    removeEveryOther(arr1);
    }

    }

    =============================================================================================
    See Quenchedput