Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to java Programming Lab 11: De-Dup Program Objective: To write a program to remove duplicates from an array Write a program that inputs an

Intro to java

Programming Lab 11: De-Dup Program

Objective: To write a program to remove duplicates from an array

Write a program that inputs an array of 10 integers from the user, and removes the duplicate array elements. Here is some sample output:

Please enter 10 integers, hitting return after each one: 5 75 10 75 5 80 10 5 5 50 You entered 5 distinct numbers: 5 75 10 80 50 

Please enter 10 integers, hitting return after each one: 1 2 3 4 5 6 7 8 9 10 You entered 10 distinct numbers: 1 2 3 4 5 6 7 8 9 10

Rules and Hints:

You must write at least 1 method in addition to the main method, and pass the array into that method as a parameter

When the program is finished, the program must have an array that stores each number only once, with no gaps and no duplicates. So you can't just skip outputting the duplicates - you have to remove them (or replace them). All the distinct numbers must be at the beginning of the array when your program finishes.

The easiest way to do this is to store only the non-repeating elements (only store a number in the array the first time you see it).

A more intuitive and more complicated way to do it is to input all 10 numbers from the user into an array, and then change the array so it contains only the distinct numbers entered by the user. To remove the duplicates, you should make it appear as if the elements hadn't been there. So do not just set duplicates to an "empty" value, but fill in the gap. That means moving all the later elements back one (kind of like when you hit backspace in the middle of a line in a text editor).

Don't use an ArrayList for this program. You need to manipulate the array yourself to make this work, in order to get full credit.

Don't use any class-level variables. Each variable must be declared inside a method.

You may assume that all the integers are between 0 and 100, and you may input them from the user however you wish.

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

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago