Third Largest in java.

You will be given 4 numbers one on each line and you are asked to find the second largest number and print them to the STDOUT . 


Input Format - 
You will take 4 integers as input from STDIN. 

Output Format 
print your result which will be the integer only to the STDOUT. 
/*
* Enter your code here. Read input from STDIN. Print your output to STDOUT.
* Your class should be named CandidateCode.
*/
import java.io.*;
import java.util.*;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
Scanner sc=new Scanner(System.in);
int [] arr=new int[4];
for(int i=0;i<4;i++){
arr[i]=sc.nextInt();
}
int thirdMax=0;
Arrays.sort(arr);
thirdMax=arr[arr.length-3];
System.out.println(thirdMax);
sc.close();
}
}

Sample Test Case: 
Sample Input:-234
213
666
879 

Sample Output 
234

Comments

Popular posts from this blog

Reasoning-Number Series

Profit and Loss

Reasoning-Letter Series