Best Answer

Method 1:

Sort the array in descending order, compare 1st and 2nd if not same , return 2nd if same return -1

Method 2:

Find the largest number in the array, initialize another array with dimension 1 less than of original. Copy the array elements from the original array minus the largest element. not select largest from the second array and compare with the previous one if not same return the second largest if same return -1

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a function in java that accepts an array of integers and returns the second largest integer in the array Return -1 if there is no second largest?
Write your answer...
Still have questions?
magnify glass
Related questions

What is the worlds largest integer?

There is no largest integers: they go on for ever.

What will be the algorithm to input n integers and output the largest one?

var largest : integer largest = array[0] for n : integer in array if n > largest largest = n endif endfor return largest

What formula represents the largest of these integers if you are thinking of n consecutive positive integers and the smallest of which is m?

For x, which is the largest integer of nconsecutive positive integers of which the smallest is m:x = m + n - 1

What is the two largest integers for 48?

The two largest integers when multiplied together is 48 are 6 and 8. To get the single highest integer when multiplying it would be 1 and 48.

What is the largest integer that divides without remainder into a set of integers?

The greatest common factor

The sum of 3 consecutive integers is 306 what is the lagest integers?

The largest integer is 103 because 101+102+103 = 306

What is the largest of 3 consecutive negative integers if the product of the larger two integers is 5 more than the smaller integer?


Find the largest of three consecutive even integers if the sum of the 2 smaller integers is 16 more than the largest integer What is the largest of the 3 integers?

Let the smallest integer be 2n, the next integer is 2n + 2, and the largest one is 2n + 4. Then, we have:2n + (2n + 2) = (2n + 4) + 164n + 2 = 2n + 202n = 18 the smallest integer2n + 2 = 18 + 2 = 20 the next one2n + 4 = 18 + 4 = 22 the largest integerCheck

What is the lagest integers f 369?

The largest integer of 369 is 3 because it represents 300

Find three positive consecutive odd integers such that the square of the middle integer increased by four times the largest integer is 173?


What is bracket function?

x = the largest integer not exceeding x

What is the single largest positive integer?

There is no such thing. whatever integer you name, no matter how large it is, I can always name an integer that's larger than the one you named. You may have not understood the question entirely. But i may be wrong. What is the SINGLE LARGEST POSITIVE INTEGER. This can be 9. 9 is a single integer, and is the largest of the positive single integers. 9 can be an answer.