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 main in java?
What is the difference between final, finally and finalize() in java?
What is the association?
What is locale in java?
What is deserialization?
How an object is serialized in java?
Can list be final in java?
What is the default access specifier for variables and methods of a class?
what is meant by Byte code concept in Java?
What are the six ways to use this keyword?
Which is the best approach for creating thread ?
What does @override mean?
What is the difference between inheritance and encapsulation?
Differentiate storage classes on the basis of their scope?
Does set allows null in java?