Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method that removes the duplicate elements from an array list of integers using the following header: public static void removeDuplicate(ArrayList < Integer >

Write a method that removes the duplicate elements from an array list of integers using the following header:

public static void removeDuplicate(ArrayList

<

Integer

>

list)

Write a test program that prompts the user to enter 10 integers to a list and displays the distinct integers in their input order separated by exactly one space.

Sample Run 1

Enter ten integers: 34 5 3 5 6 4 33 2 2 4

The distinct integers are 34 5 3 6 4 33 2

Sample Run 2

Enter ten integers: 3 3 4 4 1 1 2 2 5 5

The distinct integers are 3 4 1 2 5

Sample Run 3

Enter ten integers: 1 2 2 3 4 5 6 7 8 8

The distinct integers are 1 2 3 4 5 6 7 8

Sample Run 4

Enter ten integers: 5 4 3 2 65 4 4 5 1 5

The distinct integers are 5 4 3 2 65 1

Class Name:

Exercise11_13

fix the code:

public class Exercise11_13 {

public static void removeDuplicate(ArrayList list){

ArrayList newList = new ArrayList();

for (Integer element : list) {

if (!newList.contains(element)) {

newList.add(element);

}

}

System.out.print("The distinct integers are ");

for(Integer element : newList){

System.out.print(element+" ");

}

}

public static void main(String[] args) {

ArrayList list=new ArrayList<>();

Scanner scanner=new Scanner(System.in);

System.out.print("Enter 10 Numbers of arraylist ::");

for (int i = 0; i < 10; i++) {

list.add(scanner.nextInt());

}

removeDuplicate(list);

}

}

these are errors:

Exercise11_13.java:7: error: cannot find symbol

public static void removeDuplicate(ArrayList list){

^

symbol: class ArrayList

location: class Exercise11_13

Exercise11_13.java:9: error: cannot find symbol

ArrayList newList = new ArrayList();

^

symbol: class ArrayList

location: class Exercise11_13

Exercise11_13.java:9: error: cannot find symbol

ArrayList newList = new ArrayList();

^

symbol: class ArrayList

location: class Exercise11_13

Exercise11_13.java:37: error: cannot find symbol

ArrayList list=new ArrayList<>();

^

symbol: class ArrayList

location: class Exercise11_13

Exercise11_13.java:37: error: cannot find symbol

ArrayList list=new ArrayList<>();

^

symbol: class ArrayList

location: class Exercise11_13

Exercise11_13.java:39: error: cannot find symbol

Scanner scanner=new Scanner(System.in);

^

symbol: class Scanner

location: class Exercise11_13

Exercise11_13.java:39: error: cannot find symbol

Scanner scanner=new Scanner(System.in);

^

symbol: class Scanner

location: class Exercise11_13

7 errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

Describe three other types of visual aids.

Answered: 1 week ago

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Understand the role of corporate design in communications.

Answered: 1 week ago