1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KonstantinChe [14]
3 years ago
6

Write a method that returns a new array by eliminating the duplicate values in the array using the following method header: Publ

ic static int[] eliminateDuplicate(int[] list) Write a test program that reads in 10 integers, invokes the method, and displays the distinct numbers separated by exactly one space. Here is a sample run of the program: Enter 10 numbers: 1 2 3 2 1 6 3 4 5 2 The distinct numbers are: 1 2 3 6 4 5
Computers and Technology
1 answer:
saw5 [17]3 years ago
7 0

Answer:

Following are the program in java language

import java.util.*; // import package

class Main // main class

{

public static void main(String[] args) // main method

{

Scanner sc = new Scanner(System.in); // creating Scanner class object

int[] num= new int[10]; // declaring the array num

System.out.print("Enter 10 numbers:: ");

for (int i = 0; i < num.length; i++) // iterating over the loop

{

num[i] = sc.nextInt(); // taking 10 input integer.....

}

int[] newList1 = eliminateDuplicates(num);// calling the function eliminateDuplicates

System.out.println("The Distinct numbers are: ");

for (int i = 0; i< newList1.length; i++)

{

System.out.print(" " +newList1[i]); // display the new list

}

System.out.println();

}

public static int[] eliminateDuplicates(int[] list) // method definition as mention in question

{

int[] duplicate1 = new int[10]; // creating the array duplicate

int j = 0, I = 0; // variabe declaration

for (int i = 0; i < list.length; i++) // filling the duplicate with 0

{

duplicate1[i] = 0;

}

int count1 = 0; // variable declaration

for(int i = 0; i < list.length; i++)

{

boolean duplicate = false; // creating boolean variable

for(j = 0; j < count1; j++) // iterating over the loop

if(list[i] == duplicate1[j]) // checking the condition

{

duplicate = true; // assigning the duplicate variable to true

break;

}

if(!duplicate) //checking boolean variable duplicate

{

duplicate1[count1] = list[i];

count1++;

}

}

int [] newArray1 = new int[count1]; // creating a new array

for(int i = 0; i < count1; i++) // iterating over the loop

newArray1[i] = duplicate1[i]; // assign the element in the new array

return newArray1; // return array

}

}

Output:

Enter 10 numbers:::1

2

3

2

1

6

3

4

5

2

The Distinct numbers are:1 2 3 6 4 5

Explanation:

In this program we create a eliminateDuplicate method and passing array to them.In this function we create a duplicate array and assign 0 to them by iterating over  the loop then we check the required condition is duplicate or not by making comparison between the duplicate array and list array i.e if(list[i] == duplicate1[j]) . if matches found then it set duplicate = true; .Finally it created a new array and store the distinct element also return the new array element.  In the main method it printed the distinct elements .

You might be interested in
Asking yourself questions can help you think of what to _____, in order to get answers.
Olenka [21]
Ask your self questions can help you think of what to measure, in order to get answers.
8 0
4 years ago
Which magazie can help the public determine the best technology to use
wariber [46]
Well you can read about technology in maybe tec company magazines like apple magazines or samsung magazines on which are best to buy Hope this helps:)
3 0
4 years ago
In the context of intentional computer and network threats a ____ is a programming routine built into a system by its designer
lara31 [8.8K]

Answer:

a. backdoor

backdoor (also called a trapdoor) is a programming routine built into a system by its designer or programmer. It enables the designer or programmer to bypass system security and sneak back into the system later to access programs or files.

6 0
3 years ago
Read 2 more answers
Which employees work directly with customers, helping them make deposits and withdrawals?
d1i1m1o1n [39]
I believe the answer is customer service
5 0
3 years ago
Read 2 more answers
Sydney Bark is twenty-three years old, and is looking forward to celebrating her birthday on April 12. For her birthday, she sav
DochEvi [55]

Answer:

a future date

Explanation:

Because most people when trying to guess a password, start with basic ones like: 1234,abcde, password,l and dates (like their birthday). whereas, the person would never guess it was a future date like when the person would be 30 or when they are going on a trip .

5 0
3 years ago
Other questions:
  • True or false: although the first personal computers were available as early as the 1970's, the creation of the world wide web (
    11·1 answer
  • Software that people commonly use in the workplace to make their lives easier is called?
    6·1 answer
  • REEEEEEE I STILL NEED MORE AESTHETIC USERNAMES TO GO OFF OF PWEASE HELP IMA HAVE A PANIC ATTACK!!!... next post ima do a vote :&
    13·1 answer
  • Though it is seen as a last resort bankruptcy allows a consumer to
    6·1 answer
  • What does the cpu do (in terms of register contents and stack) when it executes a jsr instruction?
    12·1 answer
  • The program asks the user to enter the time the call is made (day, evening, or night) and the duration of the call (a number tha
    5·1 answer
  • Software refers to the physical parts of a computer.<br> a. True<br> b. False
    11·2 answers
  • Write a perl program that reads from a file containing a list of names and then displays that list to a user. The program should
    11·1 answer
  • A chain of coffee servers is sending a spreadsheet of projected costs and profits to some of its investors. When, Kyle, the admi
    7·1 answer
  • Which three statements are true of lossless compression?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!