Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a function named remove that takes an integer atom and a list as paramete

ID: 3813214 • Letter: D

Question

Define a function named remove that takes an integer atom and a list as parameters (the list does not need to be sorted). The function should return a list with the integer removed from it. If the integer occurs multiple times in the list, all occurrences should be removed. For example: remove[3, (1 2 3 4 5) = (1245) remove [3, (1 2 3 3 3 4)] = (1 2 4) remove[3, (3 3 3)] = () remove[3, (2 4 6 8)] = (2 4 6 8) Your solution must provide both the "design notation" used in class and an implementation of that design in Scheme. Test your code using the interpreter on stdlinux to check your work. As above, use only the elements we have discussed in class to write this code.

Explanation / Answer


import java.util.*;
public class Remove_element {
static List<Integer>alist=new ArrayList<Integer>();
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println("enter elements size");
       int size=sc.nextInt();
       int arr[]=new int[size];
       System.out.println("enter elements:");
       for(int i=0;i<arr.length;i++)
           arr[i]=sc.nextInt();
       System.out.println("enter element to remove:");
       int rm=sc.nextInt();
      
       alist=remove(arr,rm);
       System.out.println(alist);
   }
   private static List<Integer> remove(int[] arr, int rm) {
       for(int i=0;i<arr.length;i++){
           if(arr[i]!=rm)
               alist.add(arr[i]);
       }
       return alist;
      
   }
}

output:
enter elements size
5
enter elements:
2
1
2
3
6
enter element to remove:
2
[1, 3, 6]


i created a method called removed and it takes two arguments array and element to be removed...
it removes an element and returns an arraylist with a list of elements by removing elemnet in list..and returns to main method ..and it finally prints the list.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote