วันศุกร์ที่ 14 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.add(BigInteger val)

Description Of BigInteger: add(BigInteger val)

The java.math.BigInteger.add(BigInteger val) returns a BigInteger object whose value is (this + val).

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("456");
  BigInteger bi2 = new BigInteger("789");
  System.out.println(bi1.add(bi2)); // output : 1245 (456 + 789)
  System.out.println(bi1); // output : 456
  bi1 = bi1.add(bi2);
  System.out.println(bi1); // output : 1245
  System.out.println(bi1.add(BigInteger.valueOf(1))); // output : 1246
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 13 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.abs()

Description Of BigInteger: abs()

The java.math.BigInteger.abs() returns a BigInteger whose value is the absolute value of this BigInteger

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("456");
  BigInteger bi2 = new BigInteger("-456");
  System.out.println("Absolute value of " + bi1 + " is " + bi1.abs()); // Absolute value of 456 is 456
  System.out.println("Absolute value of " + bi2 + " is " + bi2.abs()); // Absolute value of -456 is 456
 }
}


yengo หรือ buzzcity

วันพุธที่ 12 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.and(BigInteger val)

Description Of BigInteger: and(BigInteger val)

The java.math.BigInteger.and(BigInteger val) returns a BigInteger whose value is (this & val). This method returns a negative BigInteger if and only if this and val are both negative.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("6"); // 110
  BigInteger bi2 = new BigInteger("3"); // 011
  System.out.println(bi1.and(bi2)); // 010
  
  bi1 = new BigInteger("5"); // 0101
  bi2 = new BigInteger("8"); // 1000
  System.out.println(bi1.and(bi2)); // 0000
 }
}


yengo หรือ buzzcity

วันอังคารที่ 11 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.andNot(BigInteger val)

Description Of BigInteger: andNot(BigInteger val)

The java.math.BigInteger.andNot(BigInteger val) returns a BigInteger whose value is (this & ~val). This method, which is equivalent to and(val.not()), is provided as a convenience for masking operations. This method returns a negative BigInteger if and only if this is negative and val is positive

Code Example Java BigInteger

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("6"); // 110
  BigInteger bi2 = new BigInteger("3"); // 011 ~010=101
  System.out.println(bi1.andNot(bi2)); // 100
  
  bi1 = new BigInteger("5"); // 0101
  bi2 = new BigInteger("8"); // 1000 ~1000=0111
  System.out.println(bi1.andNot(bi2)); // 0101
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 10 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.clearBit(int n)

Description Of BigInteger: clearBit(int n)

The java.math.BigInteger.clearBit(int n) The java.math.BigInteger.clearBit(int n) returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared. It computes (this & ~(1<<n)).

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("7"); 
  System.out.println(bi1.clearBit(2)); // 3
  // 7 = 111, 111 << 2 = 11100, ~11100 = 00011, 111 & 00011 = 00011 = 3
  
  int testbit = 7; // 111 , 7 << 1 = 14 = 1110, 7 << 2 = 28 = 11100
  System.out.println(testbit << 2); // 28
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 9 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.divide(BigInteger val)

Description Of BigInteger: divide(BigInteger val)

The java.math.BigInteger.divide(BigInteger val) returns a BigInteger whose value is (this / val).

Code Example Java BigInteger

import java.math.BigInteger;

public class CodeFromDoesystem {
 public static void main(String[] args) throws Exception {
  BigInteger bi1 = new BigInteger("4");
  BigInteger bi2 = new BigInteger("2");
  System.out.println(bi1.divide(bi2)); // output : 2 (4 / 2)
  System.out.println(bi2.divide(bi1)); // output : 0 (2 / 4)
  System.out.println(bi1); // output : 4
  System.out.println(bi1.divide(BigInteger.valueOf(4))); // output : 1
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 8 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.compareTo(BigInteger val)

Description Of BigInteger:compareTo(BigInteger val)

The java.math.BigInteger.compareTo(BigInteger val) compares this BigInteger with the specified BigInteger. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=).

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("7");
  BigInteger bi2 = new BigInteger("4");

  // create int object
  int res;

  // compare bi1 with bi2
  res = bi1.compareTo(bi2);

  if (res == 0) {
   System.out.println("Both values are equal");
  } else if (res == 1) {
   System.out.println("First Value is greater");
  } else if (res == -1) {
   System.out.println("Second value is greater");
  }
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 7 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.divideAndRemainder(BigInteger val)

Description Of BigInteger: divideAndRemainder(BigInteger val)

The java.math.BigInteger.divideAndRemainder(BigInteger val) returns an array of two BigIntegers containing (this / val) followed by (this % val).

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("7");
  BigInteger bi2 = new BigInteger("4");

  BigInteger bi[] = bi1.divideAndRemainder(bi2);

  System.out.println("length Of return " + bi.length);

  System.out.println("Quotient is " + bi[0]); // 7/4
  System.out.println("Remainder is " + bi[1]); // 7%4
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 6 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.doubleValue()

Description Of BigInteger: doubleValue()

The java.math.BigInteger.doubleValue() converts this BigInteger to a double. This conversion is similar to the narrowing primitive conversion from double to float.

If this BigInteger has too great a magnitude to represent as a double, it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("123456789123456789");

  double bi1Double = bi1.doubleValue();
  double bi2Double = bi2.doubleValue();

  String str1 = "Double value of " + bi1 + " is " + bi1Double;
  String str2 = "Double value of " + bi2 + " is " + bi2Double;

  // print d1, d2 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันพุธที่ 5 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.equals(Object x)

Description Of BigInteger: equals(Object x)

The java.math.BigInteger.equals(Object x) compares this BigInteger with the specified Object for equality

BigInteger.equals(Object x) method returns true if and only if the specified Object is a BigInteger whose value is numerically equal to this BigInteger

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("123");

  // compare bi1 with bi2
  Boolean b1 = bi1.equals(bi2);

  // compare bi1 with an object value 123, which is not a BigIntger
  Boolean b2 = bi1.equals("123");

  System.out.println(b1); // output true
  System.out.println(b2); // output false
 }
}


yengo หรือ buzzcity

วันอังคารที่ 4 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.flipBit(int n)

Description Of BigInteger: flipBit(int n)

The java.math.BigInteger.flipBit(int n) returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped. It computes (this ^ (1<<n))

BigInteger.flipBit(int n) method returns this ^ (1<<n)

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign value to bi1
  BigInteger bi1 = new BigInteger("8"); // 1000

  // perform flipbit operation on bi1 with index 1
  BigInteger bi2 = bi1.flipBit(1);

  System.out.println(bi2); // output 10
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 3 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.floatValue()

Description Of BigInteger: floatValue()

The java.math.BigInteger.floatValue() converts this BigInteger to a float

BigInteger.floatValue() method returns this BigInteger converted to a float

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("-123");

  // assign float values of bi1, bi2 to f1, f2
  Float f1 = bi1.floatValue();
  Float f2 = bi2.floatValue();

  // print f1, f2 values
  System.out.println(f1); // 123.0
  System.out.println(f2); // -123.0
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 2 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.gcd(BigInteger val)

Description Of BigInteger: gcd(BigInteger val)

The java.math.BigInteger.gcd(BigInteger val) returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val). It returns 0 if this==0 && val==0.

BigInteger.floatValue() This method returns a BigInteger whose value is GCD(abs(this), abs(val))

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("24");
  BigInteger bi2 = new BigInteger("32");

  // assign gcd of bi1, bi2 to bi3
  BigInteger bi3 = bi1.gcd(bi2);

  System.out.println(bi3); // output 8
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 1 พฤศจิกายน พ.ศ. 2557

java.math.BigInteger.getLowestSetBit()

Description Of BigInteger: getLowestSetBit()

The java.math.BigInteger.getLowestSetBit() returns the index of the rightmost (lowest-order) one bit in this BigInteger (the number of zero bits to the right of the rightmost one bit). It returns -1 if this BigInteger contains no one bits. It computes (this==0? -1 : log2(this & -this))

BigInteger.getLowestSetBit() This method returns the index of the rightmost one bit in this BigInteger

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");// 1000
     BigInteger bi2 = new BigInteger("7");// 0111
     BigInteger bi3 = new BigInteger("6");// 0110

     // perform getLowestSetBit on bi1, bi2
     int i1 = bi1.getLowestSetBit();
     int i2 = bi2.getLowestSetBit();
     int i3 = bi3.getLowestSetBit();

     System.out.println(i1); // output 3
     System.out.println(i2); // output 0
     System.out.println(i3); // output 1
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 31 ตุลาคม พ.ศ. 2557

java.math.BigInteger.hashCode()

Description Of BigInteger: hashCode()

The java.math.BigInteger.hashCode() returns the hash code for this BigInteger.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");
     BigInteger bi2 = new BigInteger("7");
     BigInteger bi3 = new BigInteger("6");

     int h1 = bi1.hashCode();
     int h2 = bi2.hashCode();
     int h3 = bi3.hashCode();

     // show HashCode
     System.out.println("HashCode of " + bi1 + " is " + h1);
     System.out.println("HashCode of " + bi2 + " is " + h2);
     System.out.println("HashCode of " + bi3 + " is " + h3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 30 ตุลาคม พ.ศ. 2557

java.math.BigInteger.intValue()

Description Of BigInteger: intValue()

The java.math.BigInteger.intValue() converts this BigInteger to a int

BigInteger.intValue() method returns this BigInteger converted to a int

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("-123");

  // assign int values of bi1, bi2 to i1, i2
  int i1 = bi1.intValue();
  int i2 = bi2.intValue();

  // print i1, i2 values
  System.out.println(i1); // 123
  System.out.println(i2); // -123
 }
}


yengo หรือ buzzcity

วันพุธที่ 29 ตุลาคม พ.ศ. 2557

java.math.BigInteger.longValue()

Description Of BigInteger: longValue()

The java.math.BigInteger.longValue() converts this BigInteger to a long

BigInteger.longValue() method returns this BigInteger converted to a long

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("-123");

  // assign long values of bi1, bi2 to i1, i2
  long i1 = bi1.longValue();
  long i2 = bi2.longValue();

  // print i1, i2 values
  System.out.println(i1); // 123
  System.out.println(i2); // -123
 }
}


yengo หรือ buzzcity

วันอังคารที่ 28 ตุลาคม พ.ศ. 2557

java.math.BigInteger.max(BigInteger val)

Description Of BigInteger: max(BigInteger val)

The java.math.BigInteger.max(BigInteger val) returns the maximum of this BigInteger and val.

BigInteger.max(BigInteger val) method returns the BigInteger whose value is the greater of this and val . If they are equal, either may be returned.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
     BigInteger bi2 = new BigInteger("3");

     BigInteger bi3 = bi1.max(bi2);
     System.out.println(bi3);
     System.out.println(bi3.equals(bi2));
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 27 ตุลาคม พ.ศ. 2557

java.math.BigInteger.min(BigInteger val)

Description Of BigInteger: min(BigInteger val)

The java.math.BigInteger.min(BigInteger val) returns the minimum of this BigInteger and val.

BigInteger.min(BigInteger val)method returns the BigInteger whose value is the lesser of this BigInteger and val . If they are equal, either may be returned.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
     BigInteger bi2 = new BigInteger("3");

     BigInteger bi3 = bi1.min(bi2);
     System.out.println(bi3);
     System.out.println(bi3.equals(bi1));
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 26 ตุลาคม พ.ศ. 2557

java.math.BigInteger.mod(BigInteger m)

Description Of BigInteger: mod(BigInteger m)

The java.math.BigInteger.mod(BigInteger m) returns a BigInteger whose value is (this mod m). This method differs from remainder in that it always returns a non-negative BigInteger

BigInteger.mod(BigInteger m) This method returns a BigInteger object whose value is this mod m.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
  BigInteger bi2 = new BigInteger("3");

  System.out.println(bi1.mod(bi2)); // output 2
  System.out.println(bi2.mod(bi1)); // output 1
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 25 ตุลาคม พ.ศ. 2557

java.math.BigInteger.modInverse(BigInteger m)

Description Of BigInteger: modInverse(BigInteger m)

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m)

BigInteger.modInverse(BigInteger m) BigInteger.modInverse(BigInteger m) method returns this-1 mod m

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("7");
  BigInteger bi2 = new BigInteger("40");

  System.out.println(bi1.mod(bi2)); // output 7
  System.out.println(bi1.modInverse(bi2)); // output 23 
  System.out.println(bi2.mod(bi1)); // output 5
  System.out.println(bi2.modInverse(bi1)); // output 3
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 24 ตุลาคม พ.ศ. 2557

java.math.BigInteger.modPow(BigInteger exponent, BigInteger m)

Description Of BigInteger: modPow(BigInteger exponent, BigInteger m)

The java.math.BigInteger.modPow(BigInteger exponent, BigInteger m) returns a BigInteger whose value is (thisexponent mod m) . (Unlike pow , this method permits negative exponents.)

BigInteger.modPow(BigInteger exponent, BigInteger m) method returns thisexponent mod m

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger exponent = new BigInteger("3");

  BigInteger bi1 = new BigInteger("2");
  BigInteger bi2 = new BigInteger("5");

  // perform modPow operation on bi1 using bi2 and exp
  BigInteger bi3 = bi1.modPow(exponent, bi2); // 2^3 % 5

  System.out.println(bi3); // output 3
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 23 ตุลาคม พ.ศ. 2557

java.math.BigInteger.multiply(BigInteger val)

Description Of BigInteger: multiply(BigInteger val)

The java.math.BigInteger.multiply(BigInteger val) returns a BigInteger whose value is (this * val)

BigInteger.multiply(BigInteger val) method returns this * val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");
  BigInteger bi2 = new BigInteger("5");

  System.out.println(bi1.multiply(bi2)); // output 20
  System.out.println(bi2.multiply(bi1)); // output 20
 }
}


yengo หรือ buzzcity

วันพุธที่ 22 ตุลาคม พ.ศ. 2557

java.math.BigInteger.negate()

Description Of BigInteger: negate()

The java.math.BigInteger.negate() returns a BigInteger whose value is (-this)

BigInteger.negate() method returns -this

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");
  BigInteger bi2 = new BigInteger("-5");

  System.out.println(bi1.negate()); // output -4
  System.out.println(bi1); // output 4
  System.out.println(bi2.negate()); // output 5
  System.out.println(bi2); // output 5
 }
}


yengo หรือ buzzcity

วันอังคารที่ 21 ตุลาคม พ.ศ. 2557

java.math.BigInteger.nextProbablePrime()

Description Of BigInteger: nextProbablePrime()

The java.math.BigInteger.nextProbablePrime() returns the first integer greater than this BigInteger that is probably prime. The probability that the number returned by this method is composite does not exceed 2 -100 . This method will never skip over a prime when searching: if it returns p , there is no prime q such that this < q < p

BigInteger.nextProbablePrime() method returns the first integer greater than this BigInteger that is probably prime.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("3");
  BigInteger bi2 = new BigInteger("20");
  BigInteger bi3 = new BigInteger("21");

  System.out.println(bi1.nextProbablePrime()); // output 3
  System.out.println(bi2.nextProbablePrime()); // output 23
  System.out.println(bi3.nextProbablePrime()); // output 23
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 20 ตุลาคม พ.ศ. 2557

java.math.BigInteger.not()

Description Of BigInteger: not()

The java.math.BigInteger.not() returns a BigInteger whose value is (~this) . (This method returns a negative value if and only if this BigInteger is non-negative)

BigInteger.nextProbablePrime() method returns ~this

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("6");
  BigInteger bi2 = new BigInteger("-6");

  System.out.println(bi1.not()); // output -7
  System.out.println(bi2.not()); // output 5
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 19 ตุลาคม พ.ศ. 2557

java.math.BigInteger.or(BigInteger val)

Description Of BigInteger: or(BigInteger val)

The java.math.BigInteger.or(BigInteger val) returns a BigInteger whose value is (this | val) . (This method returns a negative BigInteger if and only if either this or val is negative)

BigInteger.or(BigInteger val) method returns this | val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("3");
  BigInteger bi2 = new BigInteger("4");

  System.out.println(bi1.or(bi2)); // output 7
  System.out.println(bi2.or(bi1)); // output 7
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 18 ตุลาคม พ.ศ. 2557

java.math.BigInteger.pow(int exponent)

Description Of BigInteger: pow(int exponent)

The java.math.BigInteger.pow(int exponent) returns a BigInteger whose value is (thisexponent). Note that exponent is an integer rather than a BigInteger

BigInteger.or(BigInteger val) method returns thisexponent

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");

  System.out.println(bi1.pow(2)); // output 4 (2*2)
  System.out.println(bi1.pow(3)); // output 8 (2*2*2)
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 17 ตุลาคม พ.ศ. 2557

java.math.BigInteger.probablePrime(int bitLength, Random rnd)

Description Of BigInteger: probablePrime(int bitLength, Random rnd)

The java.math.BigInteger.probablePrime(int bitLength, Random rnd) returns a positive BigInteger that is probably prime, with the specified bitLength. The probability that a BigInteger returned by this method is composite does not exceed 2-100

BigInteger.probablePrime(int bitLength, Random rnd) method returns a BigInteger of bitLength bits that is probably prime

Code Example Java BigInteger

import java.math.BigInteger;
import java.util.Random;

public class BigIntegerExam {
 public static void main(String[] args) {
  int bitLength = 3;

  // create a random object
  Random rnd = new Random();

  BigInteger bi = BigInteger.probablePrime(bitLength, rnd);

  System.out.println(bi);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 16 ตุลาคม พ.ศ. 2557

java.math.BigInteger.remainder(BigInteger val)

Description Of BigInteger: remainder(BigInteger val)

The java.math.BigInteger.remainder(BigInteger val) returns a BigInteger whose value is (this % val)

BigInteger.remainder(BigInteger val) method returns this % val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("16");
  BigInteger bi2 = new BigInteger("3");

  BigInteger bi3 = bi1.remainder(bi2);

  System.out.println(bi1); // output 16
  System.out.println(bi3); // output 1
 }
}


yengo หรือ buzzcity

วันพุธที่ 15 ตุลาคม พ.ศ. 2557

java.math.BigInteger.setBit(int n)

Description Of BigInteger: setBit(int n)

The java.math.BigInteger.setBit(int n) returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. (Computes (this | (1<<n)))

BigInteger.setBit(int n) method returns this | (1<<n)

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");

  BigInteger bi2 = bi1.setBit(3);

  System.out.println(bi2); // output 12
 }
}


yengo หรือ buzzcity

วันอังคารที่ 14 ตุลาคม พ.ศ. 2557

java.math.BigInteger.shiftLeft(int n)

Description Of BigInteger: shiftLeft(int n)

The java.math.BigInteger.shiftLeft(int n) BigInteger whose value is (this << n). The shift distance, n , may be negative, in which case this method performs a right shift. (Computes floor(this * 2n))

BigInteger.shiftLeft(int n) method returns this << n

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("10");

  // perform leftshift operation on bi1 using 2 and -2
  BigInteger bi2 = bi1.shiftLeft(2);
  BigInteger bi3 = bi1.shiftLeft(-2);

  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 13 ตุลาคม พ.ศ. 2557

java.math.BigInteger.shiftRight(int n)

Description Of BigInteger: shiftRight(int n)

The java.math.BigInteger.shiftRight(int n) BigInteger whose value is (this >> n) . Sign extension is performed. The shift distance, n , may be negative, in which case this method performs a left shift. (Computes floor(this * 2n))

BigInteger.shiftRight(int n) method returns this >> n

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("10");

  // perform rightshift operation on bi1 using 2 and -2
  BigInteger bi2 = bi1.shiftRight(2);
  BigInteger bi3 = bi1.shiftRight(-2);

  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 12 ตุลาคม พ.ศ. 2557

java.math.BigInteger.signum()

Description Of BigInteger: signum()

The java.math.BigInteger.signum() returns the signum function of this BigInteger

BigInteger.signum() method returns -1, 0 or 1 as the value of this BigInteger is negative, zero or positive

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("0");
  BigInteger bi2 = new BigInteger("10");
  BigInteger bi3 = new BigInteger("-10");

  // assign signum results of bi1, bi2, bi3 to i1, i2, i3
  int i1 = bi1.signum();
  int i2 = bi2.signum();
  int i3 = bi3.signum();

  // print i1, i2, i3 values
  System.out.println(i1);
  System.out.println(i2);
  System.out.println(i3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 11 ตุลาคม พ.ศ. 2557

java.math.BigInteger.subtract(BigInteger val)

Description Of BigInteger: subtract(BigInteger val)

The java.math.BigInteger.subtract(BigInteger val) returns a BigInteger whose value is (this - val)

BigInteger.subtract(BigInteger val) method returns this - val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("5");
  BigInteger bi2 = new BigInteger("3");

  // assign difference of bi1 and bi2 to bi3
  BigInteger bi3 = bi1.subtract(bi2);

  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 10 ตุลาคม พ.ศ. 2557

java.math.BigInteger.testBit(int n)

Description Of BigInteger: testBit(int n)

The java.math.BigInteger.testBit(int n) returns true if and only if the designated bit is set. (Computes ((this & (1<<n)) != 0))

BigInteger.testBit(int n) method returns true if and only if the designated bit is set

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi = new BigInteger("10");

  Boolean b1 = bi.testBit(2);
  Boolean b2 = bi.testBit(3);
  
  // print b1, b2 values
  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 9 ตุลาคม พ.ศ. 2557

java.math.BigInteger.toString()

Description Of BigInteger: toString()

The java.math.BigInteger.toString() returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String) constructor, and allows for String concatenation with Java's + operator)

BigInteger.toString() method returns decimal String representation of this BigInteger

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("1234");
  BigInteger bi2 = new BigInteger("-1234");

  System.out.println(bi1.toString()); // output 1234
  System.out.println(bi2.toString()); // output -1234
 }
}


yengo หรือ buzzcity

วันพุธที่ 8 ตุลาคม พ.ศ. 2557

java.math.BigInteger.toString(int radix)

Description Of BigInteger: toString(int radix)

The java.math.BigInteger.toString(int radix) returns the String representation of this BigInteger in the given radix. If the radix is outside the range from Character.MIN_RADIX to Character.MAX_RADIX inclusive, it will default to 10 (as is the case for Integer.toString ). The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String, int) constructor)

BigInteger.toString(int radix) method returns String representation of this BigInteger in the given radix

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("16");
  BigInteger bi2 = new BigInteger("-16");

  System.out.println(bi1.toString(8));
  System.out.println(bi2.toString(2));
 }
}


yengo หรือ buzzcity

วันอังคารที่ 7 ตุลาคม พ.ศ. 2557

java.math.BigInteger.valueOf(long val)

Description Of BigInteger: valueOf(long val)

The java.math.BigInteger.valueOf(long val) returns a BigInteger whose value is equal to that of the specified long . This "static factory method" is provided in preference to a ( long ) constructor because it allows for reuse of frequently used BigIntegers

BigInteger.valueOf(long val) method returns a BigInteger with the specified value

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = BigInteger.valueOf(54L);
  BigInteger bi2 = BigInteger.valueOf(55);
  
  Long ln = new Long(56);
  BigInteger bi3 = BigInteger.valueOf(ln);
  
  System.out.println(bi1);
  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 6 ตุลาคม พ.ศ. 2557

java.math.BigInteger.xor(BigInteger val)

Description Of BigInteger: xor(BigInteger val)

The java.math.BigInteger.xor(BigInteger val) returns a BigInteger whose value is (this ^ val) . (This method returns a negative BigInteger if and only if exactly one of this and val are negative)

BigInteger.xor(BigInteger val) method returns this ^ val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");
  BigInteger bi2 = new BigInteger("2");

  // perform xor on bi1, bi2 and assign result to bi3
  BigInteger bi3 = bi1.xor(bi2);

  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 5 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.abs()

Description Of BigDecimal: abs()

The java.math.BigDecimal.abs() returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().

BigDecimal.abs() This method returns the absolute value of the called value i.e abs(this).

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal de1 = new BigDecimal("456");
  BigDecimal de2 = new BigDecimal("-456");
  System.out.println("Absolute value of " + de1 + " is " + de1.abs()); // Absolute value of 456 is 456
  System.out.println("Absolute value of " + de2 + " is " + de2.abs()); // Absolute value of -456 is 456
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 4 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.abs(MathContext mc)

Description Of BigDecimal: abs(MathContext mc)

The java.math.BigDecimal.abs(MathContext mc) returns a BigDecimal whose value is the absolute value of this BigDecimal , with rounding according to the context settings.

BigDecimal.abs(MathContext mc) method returns abs(this) , rounded as necessary

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc = new MathContext(3);
  MathContext mc1 = new MathContext(4);

  BigDecimal bg1 = new BigDecimal("123.1234");

  // assign absolute value of bg1 to bg2 rounded to 2 precision using mc
  BigDecimal bg2 = bg1.abs(mc);

  // assign absolute value of bg1 to bg3 rounded to 4 precision using mc1
  BigDecimal bg3 = bg1.abs(mc1);

  System.out.println(bg2);
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 3 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.add(BigDecimal augend)

Description Of BigDecimal: add(BigDecimal augend)

The java.math.BigDecimal.add(BigDecimal augend) returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale())

BigDecimal.add(BigDecimal augend) method returns this + augend

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("12.345");
  BigDecimal bg2 = new BigDecimal("20.123");

  // print bg1 and bg2 value
  System.out.println("Object Value is " + bg1);
  System.out.println("Augend value is " + bg2);

  // perform add operation on bg1 with augend bg2
  BigDecimal bg3 = bg1.add(bg2);

  // print bg3 value
  System.out.println("Result is " + bg3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 2 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.add(BigDecimal augend, MathContext mc)

Description Of BigDecimal: add(BigDecimal augend, MathContext mc)

The java.math.BigDecimal.add(BigDecimal augend, MathContext mc) returns a BigDecimal whose value is (this + augend) , with rounding according to the context settings. If either number is zero and the precision setting is nonzero then the other number, rounded if necessary, is used as the result

BigDecimal.add(BigDecimal augend, MathContext mc) method returns this + augend , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("12.345");
     BigDecimal bg2 = new BigDecimal("23.456");

     System.out.println("Object Value is " + bg1);
     System.out.println("Augend value is " + bg2);

     // create MathContext object with 4 precision
     MathContext mc = new MathContext(4);

     // perform add operation on bg1 with augend bg2 and context mc
     BigDecimal bg3 = bg1.add(bg2, mc);

     System.out.println("Result is " + bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 1 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.byteValueExact()

Description Of BigDecimal: byteValueExact()

The java.math.BigDecimal.byteValueExact() converts this BigDecimal to a byte , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a byte result then an ArithmeticException is thrown

BigDecimal.xor(BigInteger val) method returns this BigDecimal converted to a byte

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  // assign values to bg1 and bg2
  BigDecimal bg1 = new BigDecimal("-4");
  BigDecimal bg2 = new BigDecimal("2");

  byte i1 = bg1.byteValueExact();
  byte i2 = bg2.byteValueExact();

  // print i1,i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 30 กันยายน พ.ศ. 2557

java.math.BigDecimal.xor(BigInteger val)

Description Of BigDecimal: compareTo(BigDecimal val)

The java.math.BigDecimal.xor(BigInteger val) compares this BigDecimal with the specified BigDecimal . Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) < op > 0) , where < op > is one of the six comparison operators.

BigDecimal.compareTo(BigDecimal val) method returns -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("5");
  BigDecimal bg2 = new BigDecimal("10");

  int res = bg1.compareTo(bg2); // compare bg1 with bg2

  if (res == 0) {
   System.out.println("Both values are equal");
  } else if (res == 1) {
   System.out.println("First Value is greater");
  } else if (res == -1) {
   System.out.println("Second value is greater");
  }
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 29 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor)

Description Of BigDecimal: divide(BigDecimal divisor)

The java.math.BigDecimal.divide(BigDecimal divisor) returns a BigDecimal whose value is (this / divisor) , and whose preferred scale is (this.scale() - divisor.scale()) ; if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException is thrown.

BigDecimal.divide(BigDecimal divisor) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("5");
  BigDecimal bg2 = new BigDecimal("10");

  BigDecimal bg3 = bg1.divide(bg2); // divide bg1 with bg2

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 28 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is this.scale() . If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, int roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  System.out.println(bg1.divide(bg2, BigDecimal.ROUND_UP));
  System.out.println(bg1.divide(bg2, BigDecimal.ROUND_DOWN));
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 27 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int scale, int roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  System.out.println(bg1.divide(bg2, 2, BigDecimal.ROUND_UP));
  System.out.println(bg1.divide(bg2, 1, BigDecimal.ROUND_DOWN));
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 26 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int scale, RoundingMode roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied.

BigDecimal.xor(BigInteger val) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  System.out.println(bg1.divide(bg2, 2, RoundingMode.UP));
  System.out.println(bg1.divide(bg2, 1, RoundingMode.DOWN));
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 25 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divide(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divide(BigDecimal divisor, MathContext mc) returns a BigDecimal whose value is (this / divisor) , with rounding according to the context settings

BigDecimal.divide(BigDecimal divisor, MathContext mc) method returns this / divisor , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  MathContext mc = new MathContext(3);

  BigDecimal bg3 = bg1.divide(bg2, mc);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 24 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, RoundingMode roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is this.scale() . If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  BigDecimal bg3 = bg1.divide(bg2, RoundingMode.UP);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 23 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideAndRemainder(BigDecimal divisor)

Description Of BigDecimal: divideAndRemainder(BigDecimal divisor)

The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor) returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

BigDecimal.divideAndRemainder(BigDecimal divisor) method returns a two element BigDecimal array: the quotient (the result of divideToIntegralValue ) is the initial element and the remainder is the final element.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("10");
  BigDecimal bg2 = new BigDecimal("3");

  BigDecimal bg[] = bg1.divideAndRemainder(bg2);

     System.out.println("Quotient is " + bg[0]);
     System.out.println("Remainder is " + bg[1]);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 22 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divideAndRemainder(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) method returns a two element BigDecimal array: the quotient (the result of divideToIntegralValue ) is the initial element and the remainder is the final element.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  MathContext mc = new MathContext(3);
  
  BigDecimal bg[] = bg1.divideAndRemainder(bg2, mc);

     System.out.println("Quotient is " + bg[0]);
     System.out.println("Remainder is " + bg[1]);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 21 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor)

Description Of BigDecimal: divideToIntegralValue(BigDecimal divisor)

The java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor) returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down. The preferred scale of the result is (this.scale() - divisor.scale())

BigDecimal.divideToIntegralValue(BigDecimal divisor) method returns The integer part of this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  BigDecimal bg3 = bg1.divideToIntegralValue(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 20 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divideToIntegralValue(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc) returns a BigDecimal whose value is the integer part of (this / divisor) . Since the integer part of the exact quotient does not depend on the rounding mode, the rounding mode does not affect the values returned by this method. The preferred scale of the result is (this.scale() - divisor.scale()) . An ArithmeticException is thrown if the integer part of the exact quotient needs more than mc.precision digits.

BigDecimal.xor(BigInteger val) method returns The integer part of this / divisor .

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  MathContext mc = new MathContext(2);

  BigDecimal bg3 = bg1.divideToIntegralValue(bg2, mc);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 19 กันยายน พ.ศ. 2557

java.math.BigDecimal.doubleValue()

Description Of BigDecimal: doubleValue()

The java.math.BigDecimal.doubleValue() converts this BigDecimal to a double . This conversion is similar to the narrowing primitive conversion from double to float as defined in section 5.1.3 of The Java? Language Specification : if this BigDecimal has too great a magnitude represent as a double , it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.

BigDecimal.doubleValue() method returns this BigDecimal converted to a double

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  double bg3 = bg1.doubleValue();
  double bg4 = bg2.doubleValue();

  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 18 กันยายน พ.ศ. 2557

Java java.math BigDecimal equals(Object x)

Description Of BigDecimal: equals(Object x)

The java.math.BigDecimal.equals(Object x) compares this BigDecimal with the specified Object for equality. Unlike compareTo , this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).

BigDecimal.equals(Object x) method returns true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal 's.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("25.00");
  BigDecimal bg2 = new BigDecimal("25.00");
  BigDecimal bg3 = new BigDecimal("25");

  // assign the result of equals method to b1, b2
  Boolean b1 = bg1.equals(bg2);
  Boolean b2 = bg1.equals(bg3);

  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

java.math.BigInteger.pow(int exponent)

Description Of BigInteger: pow(int exponent)

The java.math.BigInteger.pow(int exponent) returns a BigInteger whose value is (thisexponent). Note that exponent is an integer rather than a BigInteger

BigInteger.or(BigInteger val) method returns thisexponent

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");

  System.out.println(bi1.pow(2)); // output 4 (2*2)
  System.out.println(bi1.pow(3)); // output 8 (2*2*2)
 }
}


yengo หรือ buzzcity

วันพุธที่ 17 กันยายน พ.ศ. 2557

Java java.math BigDecimal floatValue()

Description Of BigDecimal: floatValue()

The java.math.BigDecimal.floatValue() converts this BigDecimal to a float . This conversion is similar to the narrowing primitive conversion from double to float as defined in section 5.1.3 of The Java? Language Specification : if this BigDecimal has too great a magnitude to represent as a float , it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.

BigDecimal.floatValue() method returns this BigDecimal converted to a float.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("25.00");
  BigDecimal bg2 = new BigDecimal("25.00");
  BigDecimal bg3 = new BigDecimal("25");

  float b1 = bg1.floatValue();
  float b2 = bg2.floatValue();
  float b3 = bg3.floatValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 16 กันยายน พ.ศ. 2557

Java java.math BigDecimal hashCode()

Description Of BigDecimal: hashCode()

The java.math.BigDecimal.hashCode() returns the hash code for this BigDecimal . Note that two BigDecimal objects that are numerically equal but differ in scale (like 2.0 and 2.00) will generally not have the same hash code.

BigDecimal.hashCode() method returns hash code for this BigDecimal

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("25.00");
  BigDecimal bg2 = new BigDecimal("25.00");
  BigDecimal bg3 = new BigDecimal("25");

  int b1 = bg1.hashCode();
  int b2 = bg2.hashCode();
  int b3 = bg3.hashCode();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 15 กันยายน พ.ศ. 2557

Java java.math BigDecimal intValue()

Description Of BigDecimal: intValue()

The java.math.BigDecimal.intValue() converts this BigDecimal to an int . This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java? Language Specification : any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in an int , only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of this BigDecimal value as well as return a result with the opposite sign.

BigDecimal.intValue() method returns this BigDecimal converted to an int .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.00");
  BigDecimal bg2 = new BigDecimal("25.60");
  BigDecimal bg3 = new BigDecimal("25");

  int b1 = bg1.intValue();
  int b2 = bg2.intValue();
  int b3 = bg3.intValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 14 กันยายน พ.ศ. 2557

Java java.math BigDecimal intValueExact()

Description Of BigDecimal: intValueExact()

The java.math.BigDecimal.intValueExact() converts this BigDecimal to an int , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for an int result then an ArithmeticException is thrown.

BigDecimal.intValueExact() method returns this BigDecimal converted to an int .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");
  BigDecimal bg3 = new BigDecimal("25");

  int b1 = bg1.intValueExact();
  int b2 = bg2.intValueExact();
  int b3 = bg3.intValueExact();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 13 กันยายน พ.ศ. 2557

Java java.math BigDecimal longValue()

Description Of BigDecimal: longValue()

The java.math.BigDecimal.longValue() converts this BigDecimal to a long . This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java? Language Specification : any fractional part of this BigDecimal will be discarded, and if the resulting " BigInteger " is too big to fit in a long , only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of this BigDecimal value as well as return a result with the opposite sign.

BigDecimal.longValue() method returns this BigDecimal converted to a long .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.00");
  BigDecimal bg2 = new BigDecimal("25.50");
  BigDecimal bg3 = new BigDecimal("25");

  long b1 = bg1.longValue();
  long b2 = bg2.longValue();
  long b3 = bg3.longValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 12 กันยายน พ.ศ. 2557

Java java.math BigDecimal longValueExact()

Description Of BigDecimal: longValueExact()

The java.math.BigDecimal.longValueExact() converts this BigDecimal to a long , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a long result then an ArithmeticException is thrown.

BigDecimal.longValueExact() method returns this BigDecimal converted to a long .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");
  BigDecimal bg3 = new BigDecimal("25");

  long b1 = bg1.longValueExact();
  long b2 = bg2.longValueExact();
  long b3 = bg3.longValueExact();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 11 กันยายน พ.ศ. 2557

Java java.math BigDecimal max(BigDecimal val)

Description Of BigDecimal: max(BigDecimal val)

The java.math.BigDecimal.max(BigDecimal val) returns the maximum of this BigDecimal and val

BigDecimal.max(BigDecimal val) method returns the BigDecimal whose value is the greater of this BigDecimal and val . If they are equal, as defined by the compareTo method, this is returned.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");

  BigDecimal bg3 = bg1.max(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 10 กันยายน พ.ศ. 2557

Java java.math BigDecimal min(BigDecimal val)

Description Of BigDecimal: min(BigDecimal val)

The java.math.BigDecimal.min(BigDecimal val) returns the minimum of this BigDecimal and val.

BigDecimal.min(BigDecimal val) method returns the BigDecimal whose value is the lesser of this BigDecimal and val . If they are equal, as defined by the compareTo method, this is returned.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");

  BigDecimal bg3 = bg1.min(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 9 กันยายน พ.ศ. 2557

Java java.math BigDecimal movePointLeft(int n)

Description Of BigDecimal: movePointLeft(int n)

The java.math.BigDecimal.movePointLeft(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the scale. If n is negative, the call is equivalent to movePointRight(-n) . The BigDecimal returned by this call has value (this ? 10-n ) and scale max(this.scale()+n, 0) .

BigDecimal.movePointLeft(int n) method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");

  BigDecimal bg3 = bg1.movePointLeft(3); // 3 points left
  BigDecimal bg4 = bg2.movePointLeft(-2);// 2 points right

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 8 กันยายน พ.ศ. 2557

Java java.math BigDecimal movePointRight(int n)

Description Of BigDecimal: movePointRight(int n)

The java.math.BigDecimal.movePointRight(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right. If n is non-negative, the call merely subtracts n from the scale. If n is negative, the call is equivalent to movePointLeft(-n) . The BigDecimal returned by this call has value (this ? 10n ) and scale max(this.scale()-n, 0) .

BigDecimal.movePointRight(int n) method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");

  BigDecimal bg3 = bg1.movePointRight(3); // 3 points right
  BigDecimal bg4 = bg2.movePointRight(-2);// 2 points left

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 7 กันยายน พ.ศ. 2557

Java java.math BigDecimal multiply(BigDecimal multiplicand)

Description Of BigDecimal: multiply(BigDecimal multiplicand)

The java.math.BigDecimal.multiply(BigDecimal multiplicand) returns a BigDecimal whose value is (this ? multiplicand) , and whose scale is (this.scale() + multiplicand.scale()).

BigDecimal.multiply(BigDecimal multiplicand) method returns this * multiplicand

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");

  BigDecimal bg3 = bg1.multiply(bg2);

  // print bg3 values
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 6 กันยายน พ.ศ. 2557

Java java.math BigDecimal multiply(BigDecimal multiplicand, MathContext mc)

Description Of BigDecimal: multiply(BigDecimal multiplicand, MathContext mc)

The java.math.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) returns a BigDecimal whose value is (this ? multiplicand) , with rounding according to the context settings.

BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) method returns this * multiplicand , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.3");
  BigDecimal bg2 = new BigDecimal("25.2");

  MathContext mc = new MathContext(4); // 4 precision
  
  BigDecimal bg3 = bg1.multiply(bg2, mc);

  // print bg3 values
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 5 กันยายน พ.ศ. 2557

Java java.math BigDecimal negate()

Description Of BigDecimal: negate()

The java.math.BigDecimal.negate() returns a BigDecimal whose value is (-this) , and whose scale is this.scale().

BigDecimal.negate() method returns -this.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.3");
  BigDecimal bg2 = new BigDecimal("25.2");

  BigDecimal bg3 = bg1.negate();
  BigDecimal bg4 = bg2.negate();

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 4 กันยายน พ.ศ. 2557

Java java.math BigDecimal negate(MathContext mc)

Description Of BigDecimal: negate(MathContext mc)

The java.math.BigDecimal.negate(MathContext mc) returns a BigDecimal whose value is (-this) , with rounding according to the context settings.

BigDecimal.negate(MathContext mc) method returns -this , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.312");
  BigDecimal bg2 = new BigDecimal("25.24212");

  MathContext mc = new MathContext(4);// 4 precision
  
  BigDecimal bg3 = bg1.negate(mc);
  BigDecimal bg4 = bg2.negate(mc);

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันพุธที่ 3 กันยายน พ.ศ. 2557

ตัวอย่างโค้ดภาษา Java การ Copy ข้อมูล ไปที่ clipboard

ตัวอย่างโค้ดภาษา Java การ Copy ข้อมูล ไปที่ clipboard


ตัวอย่างโค้ด Java ตัวอย่างนี้ เรามาดูวิธีการก็อบปี้ข้อความไปไว้ที่คลิปบอร์ดกันครับ ซึ่งอาจจะมีโปรแกรมที่ต้องการให้กดปุ่ม Copy แล้วคัดลอกข้อความที่ต้องการ เพื่อนำไปวางในที่ต่าง ๆ ได้

ตัวอย่างโค้ด

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;

public class CodeFromDoesystem {
 public static void main(String[] args) throws Exception {
  copyToSystemClipboard("Test Copy To Clipboard");
 }

 public static void copyToSystemClipboard(String str) {
  StringSelection ss = new StringSelection(str);
  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
 }
}

ตัวอย่างโค้ดตัวอย่างนี้ เราได้ทำการสร้าง method ที่ชื่อว่า copyToSystemClipboard สำหรับให้ระบบทำการ Copy ข้อความไปไว้ใน clipboard แล้วรับพารามิเตอร์เป็น String ที่ต้องการ

yengo หรือ buzzcity

Java java.math BigDecimal plus()

Description Of BigDecimal: plus()

The java.math.BigDecimal.plus() returns a BigDecimal whose value is (+this) , and whose scale is this.scale().

BigDecimal.plus() method returns this

Code Example Java BigDecimal

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");
  BigInteger bi2 = new BigInteger("2");

  BigInteger bi3 = bi1.plus();
  BigInteger bi4 = bi2.plus();

  System.out.println(bi3);
  System.out.println(bi4);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 2 กันยายน พ.ศ. 2557

Java java.math BigDecimal plus(MathContext mc)

Description Of BigDecimal: plus(MathContext mc)

The java.math.BigDecimal.plus(MathContext mc) returns a BigDecimal whose value is (+this) , with rounding according to the context settings.

BigDecimal.plus(MathContext mc) method returns this , rounded as necessary. A zero result will have a scale of 0.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.312");
  BigDecimal bg2 = new BigDecimal("25.24212");

  MathContext mc = new MathContext(4);// 4 precision
  
  BigDecimal bg3 = bg1.plus(mc);
  BigDecimal bg4 = bg2.plus(mc);

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 1 กันยายน พ.ศ. 2557

Java java.math BigDecimal pow(int n)

Description Of BigDecimal: pow(int n)

The java.math.BigDecimal.pow(int n) returns a BigDecimal whose value is (thisn ) , The power is computed exactly, to unlimited precision.

The parameter n must be in the range 0 through 999999999, inclusive. ZERO.pow(0) returns ONE . Note that future releases may expand the allowable exponent range of this method.

BigDecimal.pow(int n) method returns thisn

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("2.242");

  BigDecimal bg2 = bg1.pow(2);

  System.out.println(bg2);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 31 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal pow(int n, MathContext mc)

Description Of BigDecimal: pow(int n, MathContext mc)

The java.math.BigDecimal.pow(int n, MathContext mc) returns a BigDecimal whose value is (thisn ) . The current implementation uses the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context settings. In general, the returned numerical value is within two ulps of the exact numerical value for the chosen precision. Note that future releases may use a different algorithm with a decreased allowable error bound and increased allowable exponent range.

The X3.274-1996 algorithm is:

-An ArithmeticException exception is thrown if
--abs(n) > 999999999
--mc.precision == 0 and n < 0
--mc.precision > 0 and n has more than mc.precision decimal digits
-if n is zero, ONE is returned even if this is zero, otherwise
--if n is positive, the result is calculated via the repeated squaring technique into a single accumulator. The individual multiplications with the accumulator use the same math context settings as in mc except for a precision increased to mc.precision + elength + 1 where elength is the number of decimal digits in n .
--if n is negative, the result is calculated as if n were positive; this value is then divided into one using the working precision specified above.
--The final value from either the positive or negative case is then rounded to the destination precision.

BigDecimal.pow(int n, MathContext mc) method returns this n using the ANSI standard X3.274-1996 algorithm

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("2.242");

  MathContext mc = new MathContext(4); // 4 precision

  BigDecimal bg2 = bg1.pow(2, mc);

  System.out.println(bg2);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 30 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal precision()

Description Of BigDecimal: precision()

The java.math.BigDecimal.precision() returns the precision of this BigDecimal . (The precision is the number of digits in the unscaled value.)

BigDecimal.precision() method returns the precision of this BigDecimal .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("0123.234");
  BigDecimal bg2 = new BigDecimal("523.0");

  // assign the result of precision of bg1, bg2 to i1 and i2
  int i1 = bg1.precision();
  int i2 = bg2.precision();

  String str1 = "The precision of " + bg1 + " is " + i1;
  String str2 = "The precision of " + bg2 + " is " + i2;

  // print the values of i1, i2
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 29 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal remainder(BigDecimal divisor)

Description Of BigDecimal: remainder(BigDecimal divisor)

The java.math.BigDecimal.remainder(BigDecimal divisor) returns a BigDecimal whose value is (this % divisor).

The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) . Note that this is not the modulo operation (the result can be negative).

BigDecimal.remainder(BigDecimal divisor) method returns this % divisor.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.234");
  BigDecimal bg2 = new BigDecimal("523.0");

  BigDecimal bg3 = bg1.remainder(bg2);

  String str = "The remainder is " + bg3;

  // print the value of bg3
  System.out.println(str);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 28 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal remainder(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: remainder(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.remainder(BigDecimal divisor, MathContext mc) returns a BigDecimal whose value is (this % divisor) , with rounding according to the context settings. The MathContext settings affect the implicit divide used to compute the remainder. The remainder computation itself is by definition exact. Therefore, the remainder may contain more than mc.getPrecision() digits.

The remainder is given by this.subtract(this.divideToIntegralValue(divisor, mc).multiply(divisor)) . Note that this is not the modulo operation (the result can be negative).

BigDecimal.remainder(BigDecimal divisor, MathContext mc) method returns this % divisor , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.234");
  BigDecimal bg2 = new BigDecimal("523.0");

  MathContext mc = new MathContext(2); // 2 precision
  
  BigDecimal bg3 = bg1.remainder(bg2, mc);

  String str = "The remainder is " + bg3;

  // print the value of bg3
  System.out.println(str);
 }
}


yengo หรือ buzzcity

วันพุธที่ 27 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal round(MathContext mc)

Description Of BigDecimal: round(MathContext mc)

The java.math.BigDecimal.round(MathContext mc) returns a BigDecimal rounded according to the MathContext settings. If the precision setting is 0 then no rounding takes place.

The effect of this method is identical to that of the plus(MathContext) method.

BigDecimal.round(MathContext mc) method returns a BigDecimal rounded according to the MathContext settings.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.234");

  MathContext mc = new MathContext(2);
  
  BigDecimal bg3 = bg1.round(mc);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 26 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal scale()

Description Of BigDecimal: scale()

The java.math.BigDecimal.scale() returns the scale of this BigDecimal . If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.

BigDecimal.scale() method returns the scale of this BigDecimal .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.0");
  BigDecimal bg2 = new BigDecimal("-1.123");

  // assign the result of scale on bg1, bg2 to i1,i2
  int i1 = bg1.scale();
  int i2 = bg2.scale();

  String str1 = "The scale of " + bg1 + " is " + i1;
  String str2 = "The scale of " + bg2 + " is " + i2;

  // print the values of i1,i2;
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 25 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal scaleByPowerOfTen(int n)

Description Of BigDecimal: scaleByPowerOfTen(int n)

The java.math.BigDecimal.scaleByPowerOfTen(int n) returns a BigDecimal whose numerical value is equal to ( this * 10n ). The scale of the result is (this.scale() - n).

BigDecimal.scaleByPowerOfTen(int n) method returns a BigDecimal whose numerical value is equal to ( this * 10n ). The scale of the result is (this.scale() - n).

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.000");
  BigDecimal bg2 = new BigDecimal("12300");

  BigDecimal bg3 = bg1.scaleByPowerOfTen(3);
  BigDecimal bg4 = bg2.scaleByPowerOfTen(-3);

  String str1 = bg1 + " raised to 10 power 3 is " + bg3;
  String str2 = bg2 + " raised to 10 power -3 is " + bg4;

  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 24 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal shortValueExact()

Description Of BigDecimal: shortValueExact()

The java.math.BigDecimal.shortValueExact() converts this BigDecimal to a short , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown.

BigDecimal.shortValueExact() method returns this BigDecimal converted to a short.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("215");
  BigDecimal bg2 = new BigDecimal("1214");

  short s1 = bg1.shortValueExact();
  short s2 = bg2.shortValueExact();

  String str1 = "Exact short value of " + bg1 + " is " + s1;
  String str2 = "Exact short value of " + bg2 + " is " + s2;

  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 23 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal signum()

Description Of BigDecimal: signum()

The java.math.BigDecimal.signum() returns the signum function of this BigDecimal .

BigDecimal.signum() method returns -1, 0, or 1 as the value of this BigDecimal is negative, zero, or positive.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("555");
  BigDecimal bg2 = new BigDecimal("0");
  BigDecimal bg3 = new BigDecimal("-555");

  int i1 = bg1.signum();
  int i2 = bg2.signum();
  int i3 = bg3.signum();

  String str1 = "The Result of Signum function on " + bg1 + " is " + i1;
  String str2 = "The Result of Signum function on " + bg2 + " is " + i2;
  String str3 = "The Result of Signum function on " + bg3 + " is " + i3;

  // print i1,i2,i3 values
  System.out.println(str1);
  System.out.println(str2);
  System.out.println(str3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 22 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal stripTrailingZeros()

Description Of BigDecimal: stripTrailingZeros()

The java.math.BigDecimal.stripTrailingZeros() returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the BigDecimal value 600.0 , which has [ BigInteger , scale ] components equals to [6000, 1], yields 6E2 with [ BigInteger , scale ] components equals to [6, -2]

BigDecimal.stripTrailingZeros() method returns a numerically equal BigDecimal with any trailing zeros removed.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.000");
  BigDecimal bg2 = new BigDecimal("012300");

  BigDecimal bg3 = bg1.stripTrailingZeros();
  BigDecimal bg4 = bg2.stripTrailingZeros();

  String str1 = bg1 + " after removing trailing zeros " + bg3;
  String str2 = bg2 + " after removing trailing zeros " + bg4;

  // print bg3, bg4 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 21 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal subtract(BigDecimal subtrahend)

Description Of BigDecimal: subtract(BigDecimal subtrahend)

The java.math.BigDecimal.subtract(BigDecimal subtrahend) returns a BigDecimal whose value is (this - subtrahend) , and whose scale is max(this.scale(), subtrahend.scale()).

BigDecimal.subtract(BigDecimal subtrahend) method returns this - subtrahend

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.123");
  BigDecimal bg2 = new BigDecimal("12.12");

  BigDecimal bg3 = bg1.subtract(bg2);

  // print bg3 value
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 20 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal subtract(BigDecimal subtrahend, MathContext mc)

Description Of BigDecimal: subtract(BigDecimal subtrahend, MathContext mc)

The java.math.BigDecimal.subtract(BigDecimal subtrahend, MathContext mc) returns a BigDecimal whose value is (this - subtrahend) , with rounding according to the context settings. If subtrahend is zero then this, rounded if necessary, is used as the result. If this is zero then the result is subtrahend.negate(mc) .

BigDecimal.subtract(BigDecimal subtrahend, MathContext mc) method returns this - subtrahend , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.123");
  BigDecimal bg2 = new BigDecimal("12.12");

  MathContext mc = new MathContext(2); // 2 precision
  
  BigDecimal bg3 = bg1.subtract(bg2, mc);

  // print bg3 value
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 19 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal toBigInteger()

Description Of BigDecimal: toBigInteger()

The java.math.BigDecimal.toBigInteger() converts this BigDecimal to a BigInteger.

To have an exception thrown if the conversion is inexact (in other words if a nonzero fractional part is discarded), use the toBigIntegerExact() method.

BigDecimal.toBigInteger() method returns this BigDecimal converted to a BigInteger

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.BigInteger;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.123");
  BigDecimal bg2 = new BigDecimal("12.92");

  BigInteger bg3 = bg1.toBigInteger();
  BigInteger bg4 = bg2.toBigInteger();

  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 18 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal toBigIntegerExact()

Description Of BigDecimal: toBigIntegerExact()

The java.math.BigDecimal.toBigIntegerExact() converts this BigDecimal to a BigInteger , checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part.

BigDecimal.toBigIntegerExact() method returns this BigDecimal converted to a BigInteger.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.BigInteger;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123");
  BigDecimal bg2 = new BigDecimal("12");

  BigInteger bg3 = bg1.toBigIntegerExact();
  BigInteger bg4 = bg2.toBigIntegerExact();

  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 17 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal toEngineeringString()

Description Of BigDecimal: toEngineeringString()

The java.math.BigDecimal.toEngineeringString() returns a string representation of this BigDecimal , using engineering notation if an exponent is needed.

BigDecimal.toEngineeringString() method returns string representation of this BigDecimal , using engineering notation if an exponent is needed.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg = new BigDecimal("1E+5");

  System.out.println("Engineering string value of " + bg + " is "
    + bg.toEngineeringString());
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 16 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal toPlainString()

Description Of BigDecimal: toPlainString()

The java.math.BigDecimal.toPlainString() returns a string representation of this BigDecimal without an exponent field. For values with a positive scale, the number of digits to the right of the decimal point is used to indicate scale. For values with a zero or negative scale, the resulting string is generated as if the value were converted to a numerically equal value with zero scale and as if all the trailing zeros of the zero scale value were present in the result.

BigDecimal.toPlainString() method returns a string representation of this BigDecimal without an exponent field.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg = new BigDecimal("1E+5");

  System.out.println("toPlainString string value of " + bg + " is "
    + bg.toPlainString());
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 15 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal toString()

Description Of BigDecimal: toString()

The java.math.BigDecimal.toString() returns the string representation of this BigDecimal , using scientific notation if an exponent is needed.

BigDecimal.toString() method returns string representation of this BigDecimal.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg = new BigDecimal("1E+5");

  System.out.println("String value of " + bg + " is " + bg.toString());
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 14 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal ulp()

Description Of BigDecimal: ulp()

The java.math.BigDecimal.ulp() returns the size of an ulp, a unit in the last place, of this BigDecimal . An ulp of a nonzero BigDecimal value is the positive distance between this value and the BigDecimal value next larger in magnitude with the same number of digits. An ulp of a zero value is numerically equal to 1 with the scale of this . The result is stored with the same scale as this so the result for zero and nonzero values is equal to [1, this.scale()] .

BigDecimal.ulp() method returns the size of an ulp of this

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123");
  BigDecimal bg2 = new BigDecimal("1.23");

  BigDecimal bg3 = bg1.ulp();
  BigDecimal bg4 = bg2.ulp();

  System.out.println("ULP value of " + bg1 + " is " + bg3);
  System.out.println("ULP value of " + bg2 + " is " + bg4);
 }
}


yengo หรือ buzzcity

วันพุธที่ 13 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal unscaledValue()

Description Of BigDecimal: unscaledValue()

The java.math.BigDecimal.unscaledValue() returns a BigInteger whose value is the unscaled value of this BigDecimal. (Computes (this * 10this.scale()))

BigDecimal.unscaledValue() method returns the unscaled value of this BigDecimal.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.BigInteger;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.12");
  BigDecimal bg2 = new BigDecimal("-245.67");

  // assign unscaledValue of bg1,bg2 to bi1,bi2
  BigInteger bi1 = bg1.unscaledValue();
  BigInteger bi2 = bg2.unscaledValue();

  String str1 = "The Unscaled Value of " + bg1 + " is " + bi1;
  String str2 = "The Unscaled Value of " + bg2 + " is " + bi2;

  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 12 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal valueOf(double val)

Description Of BigDecimal: valueOf(double val)

The java.math.BigDecimal.valueOf(double val) translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double.toString(double) method.

Note: This is generally the preferred way to convert a double (or float ) into a BigDecimal , as the value returned is equal to that resulting from constructing a BigDecimal from the result of using Double.toString(double) .

BigDecimal.valueOf(double val) method returns a BigDecimal whose value is equal to or approximately equal to the value of val.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  Double d = new Double("123.45678");

  BigDecimal bg = BigDecimal.valueOf(d);

  System.out.println(bg);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 11 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal valueOf(long val)

Description Of BigDecimal: valueOf(long val)

The java.math.BigDecimal.valueOf(long val) translates a long value into a BigDecimal with a scale of zero. This "static factory method" is provided in preference to a ( long ) constructor because it allows for reuse of frequently used BigDecimal values.

BigDecimal.valueOf(long val) method returns a BigDecimal whose value is val .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  Long d = new Long("123");

  BigDecimal bg = BigDecimal.valueOf(d);

  System.out.println(bg);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 10 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal valueOf(long unscaledVal, int scale)

Description Of BigDecimal: valueOf(long unscaledVal, int scale)

The java.math.BigDecimal.valueOf(long unscaledVal, int scale) translates a long unscaled value and an int scale into a BigDecimal . This "static factory method" is provided in preference to a ( long , int ) constructor because it allows for reuse of frequently used BigDecimal values.

BigDecimal.valueOf(long unscaledVal, int scale) method returns a BigDecimal whose value is (unscaledVal ? 10-scale).

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  Long d = new Long("123");

  BigDecimal bg = BigDecimal.valueOf(d, 4);

  System.out.println(bg);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 9 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal setScale(int newScale)

Description Of BigDecimal: setScale(int newScale)

The java.math.BigDecimal.setScale(int newScale) returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to this BigDecimal 's. Throws an ArithmeticException if this is not possible.

This call is typically used to increase the scale, in which case it is guaranteed that there exists a BigDecimal of the specified scale and the correct value. The call can also be used to reduce the scale if the caller knows that the BigDecimal has sufficiently many zeros at the end of its fractional part (i.e., factors of ten in its integer value) to allow for the rescaling without changing its value.

This method returns the same result as the two-argument versions of setScale , but saves the caller the trouble of specifying a rounding mode in cases where it is irrelevant.

Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named set X mutate field X . Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated

BigDecimal.setScale(int newScale) method returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.4567");

  BigDecimal bg2 = bg1.setScale(4);

  String str = "The value of " + bg1
    + " after changing the scale to 6 is " + bg2;

  System.out.println(str);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 8 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal setScale(int newScale, int roundingMode)

Description Of setScale(int newScale, int roundingMode)

The java.math.BigDecimal.setScale(int newScale, int roundingMode) returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value. If the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named set X mutate field X . Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated.

The new setScale(int, RoundingMode) method should be used in preference to this legacy method.

BigDecimal.setScale(int newScale, int roundingMode) method returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.556789");

  BigDecimal bg2 = bg1.setScale(4, RoundingMode.UP);

  String str = "The value of " + bg1
    + " after changing the scale to 6 is " + bg2;

  System.out.println(str);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 7 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal setScale(int newScale, RoundingMode roundingMode)

Description Of BigDecimal: setScale(int newScale, RoundingMode roundingMode)

The java.math.BigDecimal.setScale(int newScale, RoundingMode roundingMode) returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value. If the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named set X mutate field X . Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated.

BigDecimal.setScale(int newScale, RoundingMode roundingMode) method returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.556789");

  BigDecimal bg2 = bg1.setScale(4, RoundingMode.FLOOR);

  String str = "The value of " + bg1
    + " after changing the scale to 6 is " + bg2;

  System.out.println(str);
 }
}


yengo หรือ buzzcity

วันพุธที่ 6 สิงหาคม พ.ศ. 2557

Java java.math MathContext equals(Object x)

Description Of MathContext: equals(Object x)

The java.math.MathContext.equals(Object x) compares this MathContext with the specified Object for equality.

MathContext.equals(Object x) method returns true if and only if the specified Object is a MathContext object which has exactly the same settings as this object.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);
  MathContext mc3 = new MathContext(2, RoundingMode.HALF_DOWN);

  Boolean b1 = mc1.equals(mc2);
  Boolean b2 = mc1.equals(mc3);

  // print b1, b2 values
  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 5 สิงหาคม พ.ศ. 2557

Java java.math MathContext getPrecision()

Description Of MathContext: getPrecision()

The java.math.MathContext.getPrecision() returns the precision setting. This value is always non-negative.

MathContext.getPrecision() method returns an int which is the value of the precision setting.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);

  int i1 = mc1.getPrecision();
  int i2 = mc2.getPrecision();

  // print i1, i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 4 สิงหาคม พ.ศ. 2557

Java java.math MathContext getRoundingMode()

Description Of MathContext: getRoundingMode()

The java.math.MathContext.getRoundingMode() returns the roundingMode setting.

This will be one of RoundingMode.CEILING, RoundingMode.DOWN, RoundingMode.FLOOR, RoundingMode.HALF_DOWN, RoundingMode.HALF_EVEN, RoundingMode.HALF_UP, RoundingMode.UNNECESSARY, or RoundingMode.UP.

MathContext.getRoundingMode() method returns a RoundingMode object which is the value of the roundingMode setting.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2, RoundingMode.DOWN);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);

  RoundingMode i1 = mc1.getRoundingMode();
  RoundingMode i2 = mc2.getRoundingMode();

  // print i1, i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 3 สิงหาคม พ.ศ. 2557

Java java.math MathContext hashCode()

Description Of MathContext: hashCode()

The java.math.MathContext.hashCode() returns the hash code for this MathContext.

MathContext.hashCode() method returns the hash code for this MathContext.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2, RoundingMode.DOWN);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);

  int i1 = mc1.hashCode();
  int i2 = mc2.hashCode();

  // print i1, i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 2 สิงหาคม พ.ศ. 2557

Java java.math MathContext toString()

Description Of MathContext: toString()

The java.math.MathContext.toString() returns the string representation of this MathContext.

The String returned represents the settings of the MathContext object as two space-delimited words (separated by a single space character, '\u0020', and with no leading or trailing white space), as follows:

1. The string "precision=", immediately followed by the value of the precision setting as a numeric string as if generated by the Integer.toString method.

2. The string "roundingMode=", immediately followed by the value of the roundingMode setting as a word. This word will be the same as the name of the corresponding public constant in the RoundingMode enum.

Additional words may be appended to the result of toString in the future if more properties are added to this class.

MathContext.toString() method returns a String representing the context settings.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2, RoundingMode.DOWN);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);

  String i1 = mc1.toString();
  String i2 = mc2.toString();

  // print i1, i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 1 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal abs()

Java java.math BigDecimal abs()

Description Of BigDecimal: abs()


The java.math.BigDecimal.abs() returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().

BigDecimal.abs() This method returns the absolute value of the called value i.e abs(this).

Code Example Java BigDecimal


import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal de1 = new BigDecimal("456");
  BigDecimal de2 = new BigDecimal("-456");
  System.out.println("Absolute value of " + de1 + " is " + de1.abs()); // Absolute value of 456 is 456
  System.out.println("Absolute value of " + de2 + " is " + de2.abs()); // Absolute value of -456 is 456
 }
}

yengo หรือ buzzcity

วันพฤหัสบดีที่ 31 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean booleanValue()

Java java.lang Boolean booleanValue()

Description Of Boolean: booleanValue()


The java.lang.Boolean.booleanValue() returns the value of this Boolean object as a boolean primitive

Boolean.booleanValue() method returns the primitive boolean value of this object.

Code Example Java Boolean

public class BooleanExam {
 public static void main(String[] args) {
  Boolean a = new Boolean(true);
  Boolean b = new Boolean(false);

  boolean aBool = a.booleanValue();
  boolean bBool = b.booleanValue();

  System.out.println(aBool);
  System.out.println(bBool);
 }
}


yengo หรือ buzzcity

วันพุธที่ 30 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean compare(boolean x, boolean y)

Java java.lang Boolean compare(boolean x, boolean y)

Description Of Boolean: compare(boolean x, boolean y)


The java.lang.Boolean.compare(boolean x, boolean y) Compares two boolean values. The value returned is identical to what would be returned by: Boolean.valueOf(x).compareTo(Boolean.valueOf(y))

Boolean.compare(boolean x, boolean y) method returns the value 0 if x == y; a value less than 0 if !x && y; and a value greater than 0 if x && !y

Code Example Java Boolean

public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);
  Boolean x2 = new Boolean(true);
  Boolean y2 = new Boolean(true);

  int aBool = Boolean.compare(x, y);
  int bBool = Boolean.compare(x2, y2);

  System.out.println(aBool);
  System.out.println(bBool);
 }
}


yengo หรือ buzzcity