Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 getch c?

1300


What is page thrashing?

1084


Mention four important string handling functions in c languages .

1115


What is wild pointer in c with example?

1064


What is 1f in c?

2664


what are bit fields? What is the use of bit fields in a structure declaration?

2137


Why is %d used in c?

1007


What is FIFO?

1728


What is sorting in c plus plus?

980


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

1003


Why we use void main in c?

1174


I have a varargs function which accepts a float parameter?

1052


What do header files do?

1078


Why doesnt the call scanf work?

1195


Is it better to use malloc() or calloc()?

1118