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
After you save a table, the new table name appears ____.
kobusy [5.1K]
Table1/2.....hope it helps
5 0
3 years ago
Read 2 more answers
Arrange the binary number in increasing order of their arithmetic output in the decimal number system ?
tiny-mole [99]
I think the order would be

10010001-1000001 (as the biggest amount)
100101100/101
10011x101
10010x11
10100+10101 (as the least amount)

hope this helps! :)
6 0
3 years ago
Taking into account recent technological developments, what technical advances do you think are possible in the next twenty year
stiv31 [10]

Nuclear Fusion reactors may reach the prototype commercial stage , The causes and possible treatment of Alzheimers Disease  and Partial cloning of human organs for transplant therapy

Explanation:

Fusion may be an energy technology that seems to be perpetually coming over the horizon, but projects around the world such as SPARC are getting increasingly close to reactors that, although smaller in capacity, can produce net positive power in just a few years. To help accelerate discovery of permanent cure for Alzheimers, an alliance of pharmaceutical companies, nonprofit foundations and government advisers, has developed a partnership to share data from Alzheimer's clinical trials. This would definitely pave way for the permanent cure for Alzheimer. The most common method of therapeutic and reproductive cloning is somatic cell nuclear transfer (SCNT). SCNT involves separating the nucleus from a donor egg, and replacing it with the DNA from the organism meant to be cloned. Scientists could potentially clone organs with SCNT by cloning embryos, extracting the stem cells from the blastocyst, and stimulating the stem cells to differentiate into the desired organ. these three scientific and technological advancements are possible.

8 0
3 years ago
Which technology is used to uniquely identify a wlan network?
expeople1 [14]
The answer is SSID

SSID which in full stands for Service Set Identifier is used to identify a network. It ensures that clients are able to locate a WLAN in which they are attached to. In Layman’s terms, it’s the username or the primary name in a WiFi setup in which a user joins and is connected to.






8 0
3 years ago
What are different social phenomenas are you aware of that used part of a social movement, change, or cause
marin [14]

Answer:

Social change in the broadest sense is any change in social relations. Viewed this way, social change is an ever-present phenomenon in any society.

Explanation:

7 0
2 years ago
Other questions:
  • Public class Robot
    15·1 answer
  • What does an executable file contain? Program instructions written in source code. Program instructions that have been compiled
    15·1 answer
  • The presentation ____ determines the formatting characteristics of fonts and colors.
    8·1 answer
  • Was Google right to have entered the Chinese market the way it did? Did Googleâs mission compel it to create Google.cn? What spe
    9·1 answer
  • What is the largest positive number one can represent in an eight-bit 2’s complement code? Write your result in binary and decim
    7·1 answer
  • Write an algorithm to calculate the sum of integer ​
    7·1 answer
  • Aside from human user types, there are nonhuman user groups. Known as account types, __________ are implemented by the system to
    10·1 answer
  • What is meant by astigmation​
    9·2 answers
  • Topic: Video Games
    15·1 answer
  • Kkkkkkkkkkkkkkkkkk kkkkkkkkkkkkkkkkkkkkkkkkkk
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!