[Java] 배열의 합계 얻기
1. For문 public class Test { public static void main(String[] args) { int[] arr = {1,2,3,4,5,6,7,8,9}; int sum = 0; for( int i=0; i a+b); System.out.println(sum); } } 3. reduce() public class Test { public static void main(String[] args) { int[] arr = {1,2,3,4,5,6,7,8,9}; int sum = Arrays.stream(arr).reduce(0, (a,b) -> a+b); System.out.println(sum); } } 4. sum() public class Test { public static ..
2022. 4. 28.