λ°μν
Q) 10κ°μ μλ₯Ό μ λ ₯λ°μ κ·Έ μ€μμ νμλ§ λν κ°μ μΆλ ₯νλΌ.
μ½λ
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int tc=1; tc<=t; tc++) {
int[] arr = new int[10];
for(int i=0; i<arr.length; i++) {
arr[i] = scan.nextInt();
}
int sum = Arrays.stream(arr).filter(i -> i%2 == 1).sum();
System.out.println("#" + tc + " " + sum);
}
scan.close();
}
}
νμ΄
Streamμ filter() μ€κ°μ°μ°μ ν΅ν΄ νμλ₯Ό μΆμΆνκ³ , sum() λ©μλλ₯Ό ν΅ν΄ ν©μ ꡬνλ€.
λ°μν
'Algorithm' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[SW Expert Academy] - (D1)2019. λλΈλλΈ(Stream) (0) | 2020.08.08 |
---|---|
[SW Expert Academy] - (D1)2071. νκ· κ° κ΅¬νκΈ°(Stream) (0) | 2020.08.06 |
[λ°±μ€] 2562λ²: μ΅λκ°(Stream) (0) | 2020.08.04 |
[SW Expert Academy] - (D3)2817. λΆλΆ μμ΄μ ν© (0) | 2020.07.19 |
[SW Expert Academy] - (D3)4299. ννμ΄μ μ¬λμ νμ΄λ° (0) | 2020.07.17 |
λκΈ