find second largest element in array w/o using sorting
techniques? use onle one for loop.
Answer Posted / abhineet
package myPackage;
public class BiggestElementInArray {
public static void main(String agrgs[]){
int arr[] = {10,-1,-2,8,-3,-4,-5};
int max = arr[0];
int scndMax=max;
for(int i=1;i<arr.length;i++){
if(max<arr[i]){
scndMax = max;
max = arr[i];
}else if(arr[i]>scndMax || max==scndMax ){
scndMax = arr[i];
}
}
System.out.println("max::"+max);
System.out.println("scndMax::"+scndMax);
}
}
Is This Answer Correct ? | 11 Yes | 8 No |
Post New Answer View All Answers
What is the concatenation operator?
What is array in C
Explain a file operation in C with an example.
What does malloc () calloc () realloc () free () do?
How do you view the path?
What is the code in while loop that returns the output of given code?
What is the role of this pointer?
What is the difference between if else and switchstatement
What are categories used for in c?
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.
What are global variables and explain how do you declare them?
write a programming in c to find the sum of all elements in an array through function.
What are header files why are they important?
Can you return null in c?
What are the different types of data structures in c?