import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int ile = scanner.nextInt(); List<Integer> niePazyste = new ArrayList<Integer>(); int suma = 0; for (int i = 1; i < ile + 1; i++) { int liczba = scanner.nextInt(); if (liczba % 2 == 0) { suma += liczba; } else { niePazyste.add(liczba); } } sortuj(niePazyste); for (int i = 0; i < niePazyste.size(); i++) { int sumaNiepazystych = 0; for (int j = i; j < niePazyste.size(); j++) { sumaNiepazystych += niePazyste.get(j); } if (sumaNiepazystych % 2 == 0) { suma += sumaNiepazystych; break; } } if (suma != 0) { System.out.println(suma); } else { System.out.println("NIESTETY"); } } private static void sortuj(List<Integer> niePazyste){ for(int i=0;i<niePazyste.size()-1;i++){ for(int j=i+1;j<niePazyste.size();j++){ if(niePazyste.get(i).compareTo(niePazyste.get(j))==1){ int temp = niePazyste.get(i); niePazyste.set(i, niePazyste.get(j)); niePazyste.set(j, temp); } } } } public kie(){ } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class kie { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int ile = scanner.nextInt(); List<Integer> niePazyste = new ArrayList<Integer>(); int suma = 0; for (int i = 1; i < ile + 1; i++) { int liczba = scanner.nextInt(); if (liczba % 2 == 0) { suma += liczba; } else { niePazyste.add(liczba); } } sortuj(niePazyste); for (int i = 0; i < niePazyste.size(); i++) { int sumaNiepazystych = 0; for (int j = i; j < niePazyste.size(); j++) { sumaNiepazystych += niePazyste.get(j); } if (sumaNiepazystych % 2 == 0) { suma += sumaNiepazystych; break; } } if (suma != 0) { System.out.println(suma); } else { System.out.println("NIESTETY"); } } private static void sortuj(List<Integer> niePazyste){ for(int i=0;i<niePazyste.size()-1;i++){ for(int j=i+1;j<niePazyste.size();j++){ if(niePazyste.get(i).compareTo(niePazyste.get(j))==1){ int temp = niePazyste.get(i); niePazyste.set(i, niePazyste.get(j)); niePazyste.set(j, temp); } } } } public kie(){ } } |