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
Are there structures in java?
How to make a write-only class in java?
What is the difference between numeric and integer?
How do you differentiate abstract class from interface?
What is the indent key?
How do you check if a string contains only numeric digits?
What do you understand by java?
What about static nested classes in java?
What are the uses of synchronized keyword?
Explain some best practices you would apply while using collection in java?
What is difference between arraylist and list in java?
Is nullpointerexception checked or unchecked?
What is the use of flag?
Explain the inheritance?
How garbage collection is done in java?