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 / paresh thorat

package pkg;

public class Number {
public static void main(String [] args){
//int arr[]={6,4,5,2};
int arr[]={1,2,3,4,5};
int max,min=0,i;
max=arr[0];

try {
for(i=1;i<arr.length;i++){
System.out.println("Loop start");
if(arr[i]>max){
min=max;
max=arr[i];
System.out.println("Large->array "+max+"->"+arr[i]);
}
System.out.println("min-> array "+min+"->"+arr[i]);

if(max>arr[i] && arr[i]>min){
System.out.println("I am in second if loop");
min = arr[i];
System.out.println("Now min is "+min);
}

}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Second Large"+min);
}
}

Is This Answer Correct ?    5 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I dynamically allocate arrays?

1107


How can I invoke another program or command and trap its output?

1102


What is break statement?

1131


what is the different bitween abap and abap-hr?

2342


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

2083


What are integer variable, floating-point variable and character variable?

1265


What is header file in c?

1074


What are the disadvantages of a shell structure?

1356


How is = symbol different from == symbol in c programming?

1052


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

1111


What does emoji p mean?

1125


Where can I get an ansi-compatible lint?

1155


can anyone please tell about the nested interrupts?

2125


Why enum is used in c?

970


What is bubble sort technique in c?

989