My issue
how can i solve the compilation problem
My code
import java.util.*;
import java.lang.*;
import java.util.Collections;
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
class SumOfLargestAndSecondLargest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-->0){
int size = scanner.nextInt();
// Input the elements of the array
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = scanner.nextInt();
}
// Calculate the sum of the largest and second-largest integers
int sum = findSumOfLargestAndSecondLargest(array);
// Display the result
System.out.println("Sum of largest and second-largest integers: " + sum);
// Close the scanner
scanner.close();
}
private static int findSumOfLargestAndSecondLargest(int[] array) {
Arrays.sort(array);
int sum = array[array.length - 1] + array[array.length - 2];
return sum;
}
}
Learning course: Arrays using Java
Problem Link: Practice Problem in - CodeChef