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 getch c?
What is page thrashing?
Mention four important string handling functions in c languages .
What is wild pointer in c with example?
What is 1f in c?
what are bit fields? What is the use of bit fields in a structure declaration?
Why is %d used in c?
What is FIFO?
What is sorting in c plus plus?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
Why we use void main in c?
I have a varargs function which accepts a float parameter?
What do header files do?
Why doesnt the call scanf work?
Is it better to use malloc() or calloc()?