「Java」BigDecimal.compareTo()の使い方

Javaコード
package excers;
import java.math.BigDecimal;
public class BigDecimalDemo {

public static void main(String[] args) {
BigDecimal zero = new BigDecimal(“0");
BigDecimal plus = new BigDecimal(“11");
BigDecimal minus = new BigDecimal(“-22");

if ( zero.compareTo(plus) < 0 )
System.out.println(“比較演算子[ < ]");

if ( plus.compareTo(plus) == 0 )
System.out.println(“比較演算子[ == ]");

if ( zero.compareTo(minus) > 0 )
System.out.println(“比較演算子[ > ]");

if ( zero.compareTo(minus) >= 0 )
System.out.println(“比較演算子[ >= ]");

if ( zero.compareTo(minus) != 0 )
System.out.println(“比較演算子[ != ]");

if ( zero.compareTo(plus) <= 0 )
System.out.println(“比較演算子[ <= ]");

}

}
実行結果
比較演算子[ < ]
比較演算子[ == ]
比較演算子[ > ]
比較演算子[ >= ]
比較演算子[ != ]
比較演算子[ <= ]

Java

Posted by arkgame