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
Travka [436]
2 years ago
15

Write a method named numUnique that accepts a sorted array of integers as a parameter and that returns the number of unique valu

es in the array. The array is guaranteed to be in sorted order, which means that duplicates will be grouped together. For example, if a variable called list stores the following values: int[] list
Computers and Technology
1 answer:
SVEN [57.7K]2 years ago
3 0

Answer:

The method in Java is as follows:

public static int numUnique(int list[]) {  

int unique = 1;  

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

 int j = 0;  

 for (j = 0; j < i; j++) {

  if (list[i] == list[j])  

   break;  

 }

 if (i == j)  

  unique++;  

}  

return unique;  

}  

Explanation:

This line defines the numUnique method

public static int numUnique(int list[]) {

This initializes the number of unique elements to 1

int unique = 1;  

This iterates through the list

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

The following iteration checks for unique items

 int j = 0;  

<em>  for (j = 0; j < i; j++) { </em>

<em>   if (list[i] == list[j]) </em><em>If current element is unique, break the iteration</em><em> </em>

<em>    break;  </em>

<em>  } </em>

 if (i == j)  

  unique++;  

}

This returns the number of unique items in the list

return unique;  

}  

You might be interested in
Kevin is working in the Tasks folder of his Outlook account. Part of his computer screen is shown below.
klasskru [66]

Answer:

D

Explanation:

7 0
3 years ago
Advantages of monolithic operating system? ​
Lyrx [107]

Advntage:

provides CPU scheduling, memory management, file management, and other operating system functions through system calls. The other one is that it is a single large process running entirely in a single address space.

Disadvantage: if anyone service fails it leads to an entire system failure

8 0
2 years ago
What does the hard disk drive do?
Airida [17]
It stores data and retrieving digital information using one or more rigid rapidly rotating disks (platters) coated in magnetic material
4 0
4 years ago
Read 2 more answers
What are color highlights?
SVETLANKA909090 [29]

A- overusing highlights lowers the contrast and degrads the effect of the highlights.

3 0
3 years ago
Read 2 more answers
What is the internet protocol that web browsers use to request and display web pages using universal resource locators?
Rzqust [24]
HTTP protocol, stands for HyperText Transfer Protocol
6 0
3 years ago
Other questions:
  • Assume that two classes 'Temperature' and 'Sensor' have been defined. 'Temperature' has a constructor that accepts a double para
    15·1 answer
  • A _____ captures the pattern in a _____ and sends it to the computer, where special software translates the _____ into meaningfu
    8·1 answer
  • Riodic Table
    6·1 answer
  • Which one of the following, in addition to disciplinary programs and drug-testing, can employers misuse as a form of retaliation
    8·1 answer
  • What type of coverage pays for damage incurred as a result of theft, vandalism, fire or natural disaster?
    15·1 answer
  • HI brainly friends....<br> Pease thanks my answers I will also thank your answers
    11·1 answer
  • ...................is a high level, structured , open source programming language​
    10·1 answer
  • What did Bakers wear (1) in the Portugal does (2) when was author was young ???
    10·1 answer
  • What is the difference between a crosstab query and a subquery?
    11·2 answers
  • A researcher is interested in learning more about the different kinds of plants growing in different areas of the state she live
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!