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
Give a brief description of java socket programming?
What is files manifesting?
when you will synchronize a piece of your code? : Java thread
Can we declare register variable as global?
What does sprintf mean?
Do I need java on my computer?
Is nan false?
Define class?
What causes memory leak in java?
In Java list the methods that can be overridden?
What are the benefits of operations in java?
What is wrapper class example?
What are thread groups?
What are the rules for naming an array?
Explain tree set and its features?