๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[SW Expert Academy] - (D1)2019. ๋”๋ธ”๋”๋ธ”(Stream)

by ์ฃผ๋ฐœ2 2020. 8. 8.
๋ฐ˜์‘ํ˜•

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

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

์ฝ”๋“œ

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 ๋ฅผ ํ†ตํ•ด ์ถœ๋ ฅํ•œ๋‹ค.(์ˆœํšŒ)

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€