1~1000까지의 합 구하기

이진섭·2022년 11월 12일
0

java

목록 보기
5/10
import java.util.stream.IntStream;

public class FromIntRangeExample {
	public static int sum;
	public static void main(String[] args) {
		IntStream stream = IntStream.rangeClosed(1, 1000);//1~1000까지의 합 구하기
		stream.forEach(a->sum+=a);
		System.out.println("총합:"+sum);
	}

}
``

총합:500500

profile
하루하루성장하기

0개의 댓글