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
How do you determine the length of a string value that was stored in a variable?
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
How can I change their mode to binary?
Explain how do you determine a file’s attributes?
What is wrong with this initialization?
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
How do you convert strings to numbers in C?
In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
can any one provide me the notes of data structure for ignou cs-62 paper
Tell me with an example the self-referential structure?
What is the role of && operator in a program code?
What is New modifiers?
Difference between goto, long jmp() and setjmp()?
When should you not use a type cast?