Big Numbers:
~~~~~~~~~~~
Good evening to all Now I like to share about the concept Big Numbers.
Basically you cannot add the numbers 1002255534552014510040 and 258832001482255888888 using data type int.
Both the numbers cannot be declared as Int because data type int not handy to handle this many digits. So to we use the concept Big Numbers.
Java has a class in the math package to handle the big numbers. Classes such as BigInteger and BigDecimal is used to handle this numbers.
In Big Integer class we cannot use the + or * to perform add and multiply operation,Instead of that we use add() and mul() to do that operations.
//SAMPLE PROGRAM FOR BIG INTEGER:
import java.math.*;
class a
{
public static void main(String arg[])
{
BigInteger a = new BigInteger("123456789012345689 0");
BigInteger b = new BigInteger("2743561234");
//here it adds value of both a and b and stores result in variable a
a= a.add(b);
System.out.println(“ADD OF A AND B IS :”+a);
}
}
OUTPUT:
~~~~~~~~
ADD OF A AND B IS : 1234567892867018124
for detailed description of big integer refer:http://learndotjava.blogspot.in/2013/07/javamathbiginteger.html
~~~~~~~~~~~
Good evening to all Now I like to share about the concept Big Numbers.
Basically you cannot add the numbers 1002255534552014510040 and 258832001482255888888 using data type int.
Both the numbers cannot be declared as Int because data type int not handy to handle this many digits. So to we use the concept Big Numbers.
Java has a class in the math package to handle the big numbers. Classes such as BigInteger and BigDecimal is used to handle this numbers.
In Big Integer class we cannot use the + or * to perform add and multiply operation,Instead of that we use add() and mul() to do that operations.
//SAMPLE PROGRAM FOR BIG INTEGER:
import java.math.*;
class a
{
public static void main(String arg[])
{
BigInteger a = new BigInteger("123456789012345689
BigInteger b = new BigInteger("2743561234");
//here it adds value of both a and b and stores result in variable a
a= a.add(b);
System.out.println(“ADD OF A AND B IS :”+a);
}
}
OUTPUT:
~~~~~~~~
ADD OF A AND B IS : 1234567892867018124
for detailed description of big integer refer:http://learndotjava.blogspot.in/2013/07/javamathbiginteger.html
No comments:
Post a Comment