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 is use of bit field?
Explain how can I read and write comma-delimited text?
Do you know what are the properties of union in c?
What is static and auto variables in c?
Where can I get an ansi-compatible lint?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What is string concatenation in c?
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures
What is sizeof c?
Is python a c language?
How do shell structures work?
What are the types of type qualifiers in c?
Can you please compare array with pointer?
What is masking?
What is int main () in c?