package elte.java2_utikalauz5.math; import java.math.*; import java.util.Random; /** BigInteger használata. @link.forrásfájl {@docRoot}/../data/math/src BigInt.java @link.letöltés {@docRoot}/../data/math BigInt.jar @since Java 2 Útikalauz programozóknak */ class BigInt { public static void main(String args[]) { System.out.println(new BigInteger(new byte[]{0x1, 0})); // 256 System.out.println(new BigInteger(new byte[]{(byte)128})); // -128 // BigInteger(int signum, byte[] magnitude) System.out.println(new BigInteger(1, new byte[]{(byte)128})); // 128 System.out.println(new BigInteger(0, new byte[]{(byte)0})); // 0 System.out.println(new BigInteger(0, new byte[]{})); // 0 try { System.out.println(new BigInteger(0, new byte[]{(byte)128})); } catch (Exception e) { System.out.println(e); // NumberFormatEx } System.out.println(new BigInteger(-1, new byte[]{(byte)128})); // -128 // BigInteger(int numBits, Random rnd) System.out.println(new BigInteger(0, new Random())); // 0 System.out.println(new BigInteger(1, new Random())); // 1 try { System.out.println(new BigInteger(-1, new Random())); } catch (Exception e) { System.out.println(e); // IllegalArgumentEx } System.out.println(new BigInteger(32, new Random())); // BigInteger(int numBits, int certainty, Random rnd) System.out.println(new BigInteger(32, 0, new Random())); System.out.println(new BigInteger(32, 1000, new Random())); System.out.println(new BigInteger(32, -10, new Random())); System.out.println(BigInteger.valueOf(0).gcd(BigInteger.valueOf(0))); // 0 System.out.println(BigInteger.valueOf(0).gcd(BigInteger.valueOf(1))); // 1 System.out.println(BigInteger.valueOf(1).gcd(BigInteger.valueOf(0))); // 1 System.out.println(BigInteger.valueOf(1).gcd(BigInteger.valueOf(1))); // 1 System.out.println(BigInteger.valueOf(5).gcd(BigInteger.valueOf(3))); // 1 System.out.println(BigInteger.valueOf(25).gcd(BigInteger.valueOf(10))); // 5 System.out.println(BigInteger.valueOf(-25).gcd(BigInteger.valueOf(10))); // 5 Random rnd = new Random(); for (int i=1; i<100; i++) { BigInteger a = new BigInteger(64, rnd); BigInteger b = new BigInteger(64, rnd); System.out.println("gcd("+a+","+b+")="+a.gcd(b)); } } }