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
What does c mean in basketball?
How can a program be made to print the line number where an error occurs?
What is array of structure in c?
What is echo in c programming?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
Was 2000 a leap year?
What is the use of gets and puts?
What is the size of array float a(10)?
How can I use a preprocessorif expression to ?
What kind of structure is a house?
Can we change the value of static variable in c?
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
In c language can we compile a program without main() function?
Does free set pointer to null?
What is pass by reference in c?