write java code to print second max number in the array
Answer Posted / ibrahim
import java.util.ArrayList;
public class maxSec {
public static void main(String[] args) {
int maxFi=0;
int maxSe=0;
ArrayList<Integer> arl=new ArrayList<Integer>();
arl.add(4); arl.add(8); arl.add(2);
arl.add(6); arl.add(7); arl.add(8);
for(int i=0; i<arl.size(); i++){
if (maxFi< arl.get(i))
maxFi= arl.get(i);
}
for(int i=0; i<arl.size(); i++){
if (maxSe <arl.get(i)){
if (arl.get(i)<maxFi ){
maxSe=arl.get(i);
}
}
}
System.out.println(maxFi);
System.out.println(maxSe);
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what is optional in java 8?
Does java have a compiler?
Which method must be implemented by all threads?
Are variables stored in ram?
Explain throw keyword in java?
What is the super void?
Are primitives objects?
What is javac in java?
What is boolean strategy?
What is a nonetype?
State two differences between C and Java.
What is quick sort in java?
What do you mean by stream pipelining in java 8?
How do I get a substring?
What does n mean?