Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
관리 메뉴

으하하 공부일기

[SWEA] - 2019. 더블더블 (D1) 본문

SWEA/D1

[SWEA] - 2019. 더블더블 (D1)

0으하하0 2022. 4. 19. 17:34

[문제]

1부터 주어진 횟수까지 2를 곱한 값(들)을 출력하시오.

주어질 숫자는 30을 넘지 않는다.

문제 풀기

2019. 더블더블

 


[풀이]

  • Math.pow() 를 사용하여 문제 해결
  • 반환형이 double 이기 때문에 (int)를 사용하여 형변환을 해줘야함
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Solution {
	public static void main(String[] args) throws Exception {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			int n = Integer.parseInt(br.readLine());
			
			for(int i=0; i<=n; i++)
				System.out.print((int)Math.pow(2, i) + " ");
	}
}