我是靠谱客的博主 柔弱身影,最近开发中收集的这篇文章主要介绍biginteger判断相等_java biginteger怎么比较大小,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

展开全部

compareTo方法来比较,小e68a84e8a2ad62616964757a686964616f31333365643662于则返回-1,等于则返回0,大于则返回1

BigInteger a1 = new BigInteger("1");

BigInteger a2 = new BigInteger("2");

a1.compareTo(a2);

下面的例子显示math.BigInteger.compareTo()方法的用法

package com.yiibai;import java.math.*;public class BigIntegerDemo {public static void main(String[] args) {

// create 2 BigInteger objects

BigInteger bi1, bi2;

bi1 = new BigInteger("6");

bi2 = new BigInteger("3");

// create int object

int res;

// compare bi1 with bi2

res = bi1.compareTo(bi2);

String str1 = "Both values are equal ";

String str2 = "First Value is greater ";

String str3 = "Second value is greater";

if( res == 0 )

System.out.println( str1 );

else if( res == 1 )

System.out.println( str2 );

else if( res == -1 )

System.out.println( str3 );

}}

让我们编译和运行上面的程序,这将产生以下结果:

First Value is greater

最后

以上就是柔弱身影为你收集整理的biginteger判断相等_java biginteger怎么比较大小的全部内容,希望文章能够帮你解决biginteger判断相等_java biginteger怎么比较大小所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部