累乗
| 日本語 | 累乗 |
| 英語 | power |
| ふりがな | るいじょう |
| フリガナ | ルイジョウ |
ある数を数回掛け合わせること。
たとえば「2 * 2 * 2」のような計算のこと。「2の3乗」と表現する。
ただ掛け合わせればいいだけなので、基本的にはforループ等で計算できる。
また、double型の場合にはMathクラスのpow()メソッドで計算できる。
たとえば「2 * 2 * 2」のような計算のこと。「2の3乗」と表現する。
ただ掛け合わせればいいだけなので、基本的にはforループ等で計算できる。
また、double型の場合にはMathクラスのpow()メソッドで計算できる。
// Sample.java
import java.math.BigDecimal;
public class Sample
{
public static void main( String[] args )
{
// double型の場合にはMathクラスのpow()メソッドで
// 累乗を計算できます。
// 「2の3乗」を計算します。
System.out.println( Math.pow( 2, 3 ) );
// 8.0
// BigDecimalクラスを使用する場合には
// 専用のメソッドがないので普通に計算します。
BigDecimal bigDecimal = new BigDecimal( "2" );
BigDecimal result = bigDecimal;
for( int iF1 = 0; iF1 < 3 - 1; ++iF1 )
{
result = result.multiply( bigDecimal );
}
System.out.println( result );
// 8
}
}
import java.math.BigDecimal;
public class Sample
{
public static void main( String[] args )
{
// double型の場合にはMathクラスのpow()メソッドで
// 累乗を計算できます。
// 「2の3乗」を計算します。
System.out.println( Math.pow( 2, 3 ) );
// 8.0
// BigDecimalクラスを使用する場合には
// 専用のメソッドがないので普通に計算します。
BigDecimal bigDecimal = new BigDecimal( "2" );
BigDecimal result = bigDecimal;
for( int iF1 = 0; iF1 < 3 - 1; ++iF1 )
{
result = result.multiply( bigDecimal );
}
System.out.println( result );
// 8
}
}
// Sample.java
import java.math.BigDecimal;
public class Sample
{
public static void main( String[] args )
{
// double型の場合にはMathクラスのpow()メソッドで
// 累乗を計算できます。
// 「2の3乗」を計算します。
System.out.println( Math.pow( 2, 3 ) );
// 8.0
// BigDecimalクラスを使用する場合には
// 専用のメソッドがないので普通に計算します。
BigDecimal bigDecimal = new BigDecimal( "2" );
BigDecimal result = bigDecimal;
for( int iF1 = 0; iF1 < 3 - 1; ++iF1 )
{
result = result.multiply( bigDecimal );
}
System.out.println( result );
// 8
}
}




