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
What are abstract methods in java?
Explain the public class modifier?
What is the main function in java?
explain the concept of virtual method invocation in polymorphism in detail?
What is string [] args?
How to create a custom exception?
What are the parts of methodology?
What is a values collection view ?
What is volatile data type?
How many bytes is a url?
Why java is a platform independent? Explain
What is the difference between path and classpath variables?
What are the different types of collections in java?
What is the use of parse function in java?
What is the char data type?