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 can you share data between two thread in Java?
What is indexof?
why Interface used?
What is finally block?
explain different ways of using thread? : Java thread
Does java arraylist maintain insertion order?
Give a practical example of singleton class usage?
What is var keyword ?
How many bytes is a url?
How big is a gigabyte?
What is a qualifier in a sentence?
Why we use multi threading instead of multiprocessing?
Is a method a function?
Is special character in java?
What are the important methods of java exception class?