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


Please Help Members By Posting Answers For Below Questions

What is main in java?

516


What is the difference between final, finally and finalize() in java?

526


What is the association?

559


What is locale in java?

583


What is deserialization?

591






How an object is serialized in java?

540


Can list be final in java?

491


What is the default access specifier for variables and methods of a class?

574


what is meant by Byte code concept in Java?

604


What are the six ways to use this keyword?

617


Which is the best approach for creating thread ?

729


What does @override mean?

538


What is the difference between inheritance and encapsulation?

597


Differentiate storage classes on the basis of their scope?

680


Does set allows null in java?

514