Program to Find the second largest element in an array.
Answer / Viresh Kumar
To find the second-largest element in a Java array, you can use two variables: one for the largest element and another for the second-largest element. Here's a simple implementation:n```nint max = Integer.MIN_VALUE;nint secMax = Integer.MIN_VALUE;nfor (int num : arr) {n if (num > max) {n secMax = max;n max = num;n } else if (num > secMax && num != max) {n secMax = num;n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
How do you override a private method in java?
Which data type is a class in java?
What is escape analysis algorithm in JVM and how garbage collection actually worked n how it transfer the objects from one kind of space to other?
can you create interface instance ?
How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?
Define array. Tell me about 2-D array.
Can string be considered as a keyword?
String is a immutable objects . it means that string does not change........... But it will be chang......... { String s="kapil"; String s1="raj"; String s=s1; then print(.......) The String has been changed .. how it is possible and why its called immutable objects
How to split a string in java?
What is meant by nested loop?
What is keyword auto for?
When does the compiler supply a default constructor for a class?