๋ฐ์ํ
์ฝ๋
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n+1];
arr[0] = 1;
for(int i=1; i<n+1; i++) {
arr[i] = arr[i-1] * 2;
}
Arrays.stream(arr).forEach(i -> System.out.print(i + " "));
scan.close();
}
}
ํ์ด
์ฃผ์ด์ง n+1๊น์ง 2์ฉ ๊ณฑํด์ ๋ฐฐ์ด์ ์ ์ฅํ๊ณ , forEach ๋ฅผ ํตํด ์ถ๋ ฅํ๋ค.(์ํ)
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SW Expert Academy] - (D2)1974. ์ค๋์ฟ ๊ฒ์ฆ (0) | 2020.08.10 |
---|---|
[SW Expert Academy] - (D1)1933. ๊ฐ๋จํ N์ ์ฝ์(Stream) (0) | 2020.08.09 |
[SW Expert Academy] - (D1)2071. ํ๊ท ๊ฐ ๊ตฌํ๊ธฐ(Stream) (0) | 2020.08.06 |
[SW Expert Academy] - (D1)2072. ํ์๋ง ๋ํ๊ธฐ(Stream) (4) | 2020.08.05 |
[๋ฐฑ์ค] 2562๋ฒ: ์ต๋๊ฐ(Stream) (0) | 2020.08.04 |
๋๊ธ