subject

I'm trying to create a java program using arraylists to find the median of the list. The lists can be either even or odd in length. If the list is even in length then I take the greater median value. This is what I have so far

int go( List list )
{

Collections. sort(list);

int middle = list. size() / 2;
int size = list. size() % 2;
int midplus = middle + 1;

if (size == 1)
{
return list. get(middle);
}
else
{
return list. get(midplus);
}

}

I keep getting an ArrayIndexOutOfBounds exception and I do not know why.

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:40, Bgreene2377
In this lab, you complete a python program that calculates an employee's annual bonus. input is an employee's first name, last name, salary, and numeric performance rating. if the rating is 1, 2, or 3, the bonus rate used is .25, .15, or .1 respectively. if the rating is 4 or higher, the rate is 0. the employee bonus is calculated by multiplying the bonus rate by the annual salary.
Answers: 1
image
Computers and Technology, 24.06.2019 17:00, kappy10
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
image
Computers and Technology, 25.06.2019 00:30, jennynmike03
Which of these serves as a bridge between the programming team and the audio team?
Answers: 2
image
Computers and Technology, 25.06.2019 08:30, asapmechee
Uses an iterative process that repeats the design, expansion, and testing steps as needed, based on feedback from users.
Answers: 1
You know the right answer?
I'm trying to create a java program using arraylists to find the median of the list. The lists can b...

Questions in other subjects: