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.
Sample Test Case:
Sample Input:-234
213
666
879
Sample Output -
234
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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
Post a Comment