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
Blogs may refer to any kind of communication over the internet is true​
Sliva [168]

Answer:

Yes It's true but You forgot email

Explanation:

6 0
3 years ago
Help me<br>please answers this questions<br>​
kobusy [5.1K]

Answer:

RSI stands for repeating similar movements

3 0
2 years ago
Sharon is thinking about opening a bakery. She knows she wants to set her own hours, reduce her stress and make a profit. But sh
kondaur [170]
C would not be a beginner move.

hope it helps
6 0
3 years ago
What technology would it take to make a balloon that doesn't pop?
SpyIntel [72]
The balloon has to be made out of old truck tiers at lest 20 ilb
7 0
3 years ago
PLEASE HELP ASAP I WILL GIVE BRAINLIEST TO CORRECT ANSWER
salantis [7]
The correct answer is letter b
8 0
3 years ago
Read 2 more answers
Other questions:
  • How to tell if screen or screen protector is cracked?
    5·2 answers
  • Janice, who is 15, posts a picture of herself drinking alcohol and making an obscene gesture on her social networking page. Whic
    11·2 answers
  • They begin beating it with a hose to find out what it really means. How does the figurative language in this excerpt reveal Coll
    9·2 answers
  • An electronic spreadsheet is a type of<br> archive.<br> database.<br> document.<br> periodical.
    15·2 answers
  • Buenas , ayudenme con esta tarea de excel 2016
    6·1 answer
  • Write about virus in five points.​
    8·1 answer
  • Two technicians are discussing Newton's first law of motion. Technician A says that a lightweight vehicle requires as
    8·1 answer
  • State the difference between a monitor and a television​
    5·2 answers
  • Please help……Your friend is taking images from all over the internet without giving credit to the sources. He tells you that it’
    6·1 answer
  • Which is NOT true?<br> 9 + 4 = 17 - 4<br> 8 + 7 = 14 + 3<br> 11 = 19 - 8<br> 5 + 8 = 20 - 7
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!