문제
1부터 주어진 횟수까지 2를 곱한 값(들)을 출력하시오.
주어질 숫자는 30을 넘지 않는다. |
1. 코드
import java.util.Scanner;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0; i<=n; i++){
System.out.print((int)Math.pow(2,i) +" ");
}
}
}
2. 출력
1 2 4 8 16 32 64 128 256
더보기
Math.pow 앞에 int형을 안붙이면 실수형으로 출력됨
'SW expert Academy > D1' 카테고리의 다른 글
[SW expert Academy] 1545번 거꾸로 출력해 보아요 (0) | 2023.04.14 |
---|---|
[SW Expert Academy] 1936번 1대1 가위바위보 (0) | 2023.04.14 |
[SW Expert Academy] 1933번 간단한 N 의 약수 (0) | 2023.04.14 |
[SW Expert Academy] 1938번 아주 간단한 계산기 (0) | 2023.04.14 |
[SW Expert Academy] 2025번 N줄덧셈 (0) | 2023.04.14 |