Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class SomeMatrixTaskString {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int rowN = Integer.parseInt(reader.readLine());
- int colM = Integer.parseInt(reader.readLine());
- String rowWithMostEvenNumbers = "";
- int mostEvens = 0;
- for (int i = 0; i < rowN; i++) {
- String row = reader.readLine();
- int[] array = Arrays.stream(row.split(" "))
- .mapToInt(Integer::parseInt).toArray();
- int countEvens = 0;
- for (int num : array) {
- if (num % 2 == 0) {
- countEvens++;
- }
- }
- if (countEvens > mostEvens) {
- mostEvens = countEvens;
- rowWithMostEvenNumbers = row;
- }
- }
- System.out.println(rowWithMostEvenNumbers);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement