CodeChef - Second Largest

Second Largest from CodeChef

CodeChef - Second Largest

Problem

Three numbers A, B and C are the inputs. Write a program to find the second largest among them.

Input

The first line contains an integer T, the total number of test cases. The T lines follow, each line contains three integers A, B and C.

Output Format

For each test case, display the second largest among A, B and C, in a new line.

Constraints

  • 1 <= T <= 1000
  • 1 <= A, B, C <= 1000000

Solution in Java

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef2{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		
		int num[]=new int[3];
		while(t-- >0){
		    for(int i=0;i<num.length;i++){
		        num[i]=in.nextInt();
		    }
		   Arrays.sort(num);
		   System.out.println(num[num.length-2]);
		}
        in.close();
    }
}