← Каталог
Java — консольные задачи — 7.2. Несколько тестов в одном запуске
Фрагмент из «Java — консольные задачи»: 7.2. Несколько тестов в одном запуске.
import java.util.Scanner;
public class ManyTests {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int test = 0; test < t; test++) {
int n = sc.nextInt();
long sum = 0;
for (int i = 0; i < n; i++) {
sum += sc.nextInt();
}
System.out.println(sum);
}
sc.close();
}
} import java.util.Scanner;
public class ManyTests {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int test = 0; test < t; test++) {
int n = sc.nextInt();
long sum = 0;
for (int i = 0; i < n; i++) {
sum += sc.nextInt();
}
System.out.println(sum);
}
sc.close();
}
}