: ์ฃผ์ํ ์ ์ ๊ฒฐ๊ณผ๊ฐ์ด doubleํ์ผ๋ก ์ถ๋ ฅ๋๋ค๋ ๊ฒ์ด๋ค!!
int๊ฐ์ผ๋ก ํ์ํ๋ค๋ฉด ํ๋ณํ์ ํด์ค์ผํ๋ค.
public class PowerExample {
public static void main(String[] args) {
// 2์ 3์ ๊ณฑ (2^3)
double result1 = Math.pow(2, 3);
System.out.println("2์ 3์ ๊ณฑ: " + result1); // 8.0
// 5์ 2์ ๊ณฑ (5^2)
double result2 = Math.pow(5, 2);
System.out.println("5์ 2์ ๊ณฑ: " + result2); // 25.0
// 10์ 0์ ๊ณฑ (10^0)
double result3 = Math.pow(10, 0);
System.out.println("10์ 0์ ๊ณฑ: " + result3); // 1.0
// 3์ -1์ ๊ณฑ (3^-1)
double result4 = Math.pow(3, -1);
System.out.println("3์ -1์ ๊ณฑ: " + result4); // 0.3333...
}
}
public class PowerExample {
public static void main(String[] args) {
int n = 2;
int n2 = 3;
// Math.pow์ ๊ฒฐ๊ณผ๋ฅผ int๋ก ๋ณํ
int result = (int) Math.pow(n, n2);
System.out.println("2์ 3์ ๊ณฑ: " + result); // 8
}
}