자바기초 #8 Math.pow

minsekim1·2022년 6월 6일

java

목록 보기
8/13

제곱 계산

Math.pow(5,2) 는 25이다.
=> 5^2

은행 복리 문제

public class Money {
  public static void main(String[] args) {
    // 변수 생성
    int a = 10000000;
    double r = 0.03;
    double n = 5;
    
    // 계산
    int s = (int)(a * Math.pow(1+r, n));
    
    // 출력
    System.out.printf("만기 금액: %d 원", s);
  }
}

s = a * (1+r)^n는
s = a * Math.pow(1+r, n)로 바꿀 수 있다.

profile
안녕하세요! 백엔드로 변신중인 4년차 풀스택 개발자 민세킴입니다.

0개의 댓글