λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Algorithm

[SW Expert Academy] - (D1)1933. κ°„λ‹¨ν•œ N의 μ•½μˆ˜(Stream)

by 주발2 2020. 8. 9.
λ°˜μ‘ν˜•

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PhcWaAKIDFAUq&categoryId=AV5PhcWaAKIDFAUq&categoryType=CODE

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

 

μ½”λ“œ

import java.util.Scanner;
import java.util.stream.IntStream;

public class κ°„λ‹¨ν•œNμ˜μ•½μˆ˜_1933 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
		
		IntStream.rangeClosed(1, N).filter(i -> (N%i == 0)).forEach(i -> System.out.print(i + " "));
		
		scan.close();
	}

}

 

풀이

rangeClose(1, N)

 - 1 ~ NκΉŒμ§€

 

filter(i -> (N%i == 0)

 - N%i == 0인경우(iκ°€ N의 μ•½μˆ˜μΈκ²½μš°)

 

forEach()

 - μ•½μˆ˜μΈ i 좜λ ₯.

λ°˜μ‘ν˜•

λŒ“κΈ€