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
How can I dynamically allocate arrays?
How can I invoke another program or command and trap its output?
What is break statement?
what is the different bitween abap and abap-hr?
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.
What are integer variable, floating-point variable and character variable?
What is header file in c?
What are the disadvantages of a shell structure?
How is = symbol different from == symbol in c programming?
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
What does emoji p mean?
Where can I get an ansi-compatible lint?
can anyone please tell about the nested interrupts?
Why enum is used in c?
What is bubble sort technique in c?