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
Does the order of public and static declaration matter in main method?
What is the final keyword denotes?
What is the importance of main method in Java?
What is the difference between replace and replace all?
Does java linked list allow duplicates?
Does collectionutils isempty check for null?
How many bits is a float?
What are the restrictions that are applied to the java static methods?
What does isempty () do in java?
What is stream api in java8?
What is the finalize method do?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
What are the characteristics of Final,Finally and Finalize keywords.
List some features of the abstract class.
What are the basics of core java?