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


Please Help Members By Posting Answers For Below Questions

What is the concatenation operator?

612


What is array in C

710


Explain a file operation in C with an example.

663


What does malloc () calloc () realloc () free () do?

560


How do you view the path?

670






What is the code in while loop that returns the output of given code?

1316


What is the role of this pointer?

549


What is the difference between if else and switchstatement

1312


What are categories used for in c?

568


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.

14964


What are global variables and explain how do you declare them?

578


write a programming in c to find the sum of all elements in an array through function.

1708


What are header files why are they important?

580


Can you return null in c?

597


What are the different types of data structures in c?

608