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
How do you decide when to use arraylist and linkedlist?
Can we declare register variable as global?
explain the difference between jdk and jvm?
What is mean by collections in java?
What is the significance of java packages?
Is jdk required on each machine to run a java program?
Explain how hashmap works?
How do you initialize an arraylist in java?
What is the full meaning of java?
Explain illegalmonitorstateexception and when it will be thrown?
What is the difference between super class & sub class?
What is locale?
Why is string buffer better than string ?
What are the advantages of assembly language?
What is Mutex (Mutual Exclusion Object) ?