Write a method named numUnique that accepts a sorted array of integers as a parameter and that returns the number of unique values 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

Answers

Answer 1

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;  

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

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

   break;  

 }

 if (i == j)  

  unique++;  

}

This returns the number of unique items in the list

return unique;  

}  


Related Questions

Gamification and virtual reality is the future of education

Answers

Answer:

Education is expected to be the fourth largest sector for VR investment. VR in education is predicted to be a $200 million industry by 2020, and a $700 million industry by 2025. 97% of students would like to study a VR course.

Explanation:

How to do brainliest

Answers

If the reply that someone put has a blue crown you click it and it will give them brainliest but it usually won’t work unless there are two answers

What email program would you suggest and why?

Answers

Answer:

An email program

Explanation:

And why?

Answer:

I would suggest g m a i l.

Explanation:

I use G m a i l all the time and I think it is easy to use! A lot of people think it is great too! :)

Write a program that reads an integer between o and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all the digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10=2 and 932/10 =93. Here is a sample run:
Enter a number between 0 and 1000 : 999
The sum of digits is 27.

Answers

Answer:

Answered below

Explanation:

#Program is written in Python programming language

digit = 0

sum = 0

num = int(input("Enter a number between 0 and 1000: ")

#Check that number is within the valid range

if num > 0 and num <= 1000:

while num != 0:

#Isolate each digit

digit = num % 10

sum = sum + digit

#Remove isolated digit from number

num = num/10

else:

print("Number is not within valid range")

#print total sum of digits

print(sum)

Other Questions
1.) Determine if the coordinate points represent a function. (1.3). (2.6). (3.9). (4. 12). (5.15 O Function O Not a FunctionO both How did European goods impact the lives of native tribes xy^2-x^2yx= -1y= -2 the value of y is four less than one-third of x. what is the equation of the relationship Which type of college credit program does the statement describe?In a(an) A) international Baccalaureate B) Advanced PlacementC) Dual CreditD) Articulated Creditprogram, a student must pass an exam at the end of course with a 3 out of 5 in order to get collegecredit. Some colleges require even higher scores or they will not accept the credit. Which if the following is currently America's number-one cause if death? February 29th is on Sunday. on what day will the next February 29th be? A game of chance involves spinning a wheel with 4 number on it. The wheel is designed so that the result of each spin Xhas the following probability distribution. 2 3 Result of a spin .x Probability : 0.50 (a) Find and interpret the mean of X. (b) Find and interpret the standard deviation of x. (c) It costs a player $5 for a single spin. The player will receive (in dollars) three times the number that appears. So the profit for one play of this game is Yeur 5. What is the mean and standard deviation of 7 Whitman uses rhyming couplets, but he intentionally breaks the flow and pattern of the couplets in the last four lines of each stanza. Notice, too, that rhymes are sometimes perfect (ex: "done" and "won"), but other times the rhymes are slant or near (ex: "bells" and "trills"). Why, do you suppose, Whitman decided to subtly break the traditional pattern? What was the reason Chief John Ross joined the Confederacy at first.I'll give brainly to the person who gives an actual reason. Need as soon as possible URGENT! LAST QUESTION OF MY HW! I've reposted this multiple times but no one has answered, please leave an explanation if you know the answer. I will give Brainliest! 1. Why is Cortes' letter a primary source?2. Is there any information in his letter that he did not actually observe? How do you reconcile this fact with the idea that this is a primary source? Can a document be partially primary and partially secondary? (i.e., written by someone who did not witness the events or experience the emotion?)3. What can you infer about Cortes motives in writing about the wonders of Tenochtitlan and the Aztecs? Why did he choose to write about the topics he addressed in this letter? Who is is intended audience, and how might that have influenced the letter?4. Using Cortes' comments in the first two paragraphs, what assumptions can you make about the wealth of the Aztec state?5. List three characteristics of the Aztec religion. What religious practice did Cortes attempt to do away with? Do you think that he could have been successful? Solve each of the following problems to 3 sig figs and correct Sl units, showing all work.1. A cart with a mass of 45.0 kg is being pulled to the right with a force of 250 N giving it anacceleration of 1.30 m/s2. The wheels of the cart are locked and the cart must be dragged.a) Draw a free body diagram of the cart.b) Calculate the net force acting on the cart.c) Create a force table and fill it in.d) Find the coefficient of kinetic friction. The access code for a car's security system consists of four digits. The second digit cannot be zero and the last digit must be odd. How many different codes are available? In an electrically neutral atom of any element, there are equal numbers of A. Protons and neurons. B. electrons and procons. C. electrons and neurrons. D. atomic number and atomia mess. 5 can someone please help me its 15 points of my major grade.. 100 POINTS!!!! I WILL GIVE BRAINLIEST TO WHO ANSWERS CORRECTLY!!!!!!!!!!!!Please give a food web for a blue viper Use the domain (1/2, 1, 2, 4, 8) to plot the points on the graph for the given equation. The grid marks represent one unit,the horizontal red line represents the x-axis, and the vertical red line represents the y-axis.y = log 2 x mention the importance of child rights