<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDevelopment_Class%2FBig_Integer</id>
		<title>Java/Development Class/Big Integer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FDevelopment_Class%2FBig_Integer"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Development_Class/Big_Integer&amp;action=history"/>
		<updated>2026-04-22T15:45:56Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Development_Class/Big_Integer&amp;diff=8461&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Development_Class/Big_Integer&amp;diff=8461&amp;oldid=prev"/>
				<updated>2010-06-01T07:06:47Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:06, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Development_Class/Big_Integer&amp;diff=8460&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Development_Class/Big_Integer&amp;diff=8460&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:46Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Another Big Integer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2000 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book (recommended),&lt;br /&gt;
 * visit http://www.davidflanagan.ru/javaexamples2.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.BufferedReader;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStreamReader;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.math.BigInteger;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * This program displays factorials as the user enters values interactively&lt;br /&gt;
 */&lt;br /&gt;
public class FactQuoter {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    // This is how we set things up to read lines of text from the user.&lt;br /&gt;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;
    // Loop forever&lt;br /&gt;
    for (;;) {&lt;br /&gt;
      // Display a prompt to the user&lt;br /&gt;
      System.out.print(&amp;quot;FactQuoter&amp;gt; &amp;quot;);&lt;br /&gt;
      // Read a line from the user&lt;br /&gt;
      String line = in.readLine();&lt;br /&gt;
      // If we reach the end-of-file,&lt;br /&gt;
      // or if the user types &amp;quot;quit&amp;quot;, then quit&lt;br /&gt;
      if ((line == null) || line.equals(&amp;quot;quit&amp;quot;))&lt;br /&gt;
        break;&lt;br /&gt;
      // Try to parse the line, and compute and print the factorial&lt;br /&gt;
      try {&lt;br /&gt;
        int x = Integer.parseInt(line);&lt;br /&gt;
        System.out.println(x + &amp;quot;! = &amp;quot; + Factorial4.factorial(x));&lt;br /&gt;
      }&lt;br /&gt;
      // If anything goes wrong, display a generic error message&lt;br /&gt;
      catch (Exception e) {&lt;br /&gt;
        System.out.println(&amp;quot;Invalid Input&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/**&lt;br /&gt;
 * This version of the program uses arbitrary precision integers, so it does not&lt;br /&gt;
 * have an upper-bound on the values it can compute. It uses an ArrayList object&lt;br /&gt;
 * to cache computed values instead of a fixed-size array. An ArrayList is like&lt;br /&gt;
 * an array, but can grow to any size. The factorial() method is declared&lt;br /&gt;
 * &amp;quot;synchronized&amp;quot; so that it can be safely used in multi-threaded programs. Look&lt;br /&gt;
 * up java.math.BigInteger and java.util.ArrayList while studying this class.&lt;br /&gt;
 * Prior to Java 1.2, use Vector instead of ArrayList&lt;br /&gt;
 */&lt;br /&gt;
class Factorial4 {&lt;br /&gt;
  protected static ArrayList table = new ArrayList(); // create cache&lt;br /&gt;
  static { // Initialize the first element of the cache with !0 = 1.&lt;br /&gt;
    table.add(BigInteger.valueOf(1));&lt;br /&gt;
  }&lt;br /&gt;
  /** The factorial() method, using BigIntegers cached in a ArrayList */&lt;br /&gt;
  public static synchronized BigInteger factorial(int x) {&lt;br /&gt;
    if (x &amp;lt; 0)&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;x must be non-negative.&amp;quot;);&lt;br /&gt;
    for (int size = table.size(); size &amp;lt;= x; size++) {&lt;br /&gt;
      BigInteger lastfact = (BigInteger) table.get(size - 1);&lt;br /&gt;
      BigInteger nextfact = lastfact.multiply(BigInteger.valueOf(size));&lt;br /&gt;
      table.add(nextfact);&lt;br /&gt;
    }&lt;br /&gt;
    return (BigInteger) table.get(x);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * A simple main() method that we can use as a standalone test program for&lt;br /&gt;
   * our factorial() method.&lt;br /&gt;
   */&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    for (int i = 0; i &amp;lt;= 50; i++)&lt;br /&gt;
      System.out.println(i + &amp;quot;! = &amp;quot; + factorial(i));&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A trivial reverse-polish stack-based calculator for big numbers ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.math.BigDecimal;&lt;br /&gt;
import java.util.Stack;&lt;br /&gt;
/** A trivial reverse-polish stack-based calculator for big numbers */&lt;br /&gt;
public class BigNumCalc {&lt;br /&gt;
  /** an array of Objects, simulating user input */&lt;br /&gt;
  public static Object[] testInput = {&lt;br /&gt;
    new BigDecimal(&amp;quot;3419229223372036854775807.23343&amp;quot;),&lt;br /&gt;
    new BigDecimal(&amp;quot;2.0&amp;quot;),&lt;br /&gt;
    &amp;quot;*&amp;quot;,&lt;br /&gt;
  };&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    BigNumCalc calc = new BigNumCalc();&lt;br /&gt;
    System.out.println(calc.calculate(testInput));&lt;br /&gt;
  }&lt;br /&gt;
  Stack s = new Stack();&lt;br /&gt;
  public BigDecimal calculate(Object[] input) {&lt;br /&gt;
    BigDecimal tmp;&lt;br /&gt;
    for (int i = 0; i &amp;lt; input.length; i++) {&lt;br /&gt;
      Object o = input[i];&lt;br /&gt;
      if (o instanceof BigDecimal) {&lt;br /&gt;
        s.push(o);&lt;br /&gt;
      } else if (o instanceof String) {&lt;br /&gt;
        switch (((String)o).charAt(0)) {&lt;br /&gt;
        // + and * are commutative, order doesn&amp;quot;t matter&lt;br /&gt;
        case &amp;quot;+&amp;quot;:&lt;br /&gt;
          s.push(((BigDecimal)s.pop()).add((BigDecimal)s.pop()));&lt;br /&gt;
          break;&lt;br /&gt;
        case &amp;quot;*&amp;quot;:&lt;br /&gt;
          s.push(((BigDecimal)s.pop()).multiply((BigDecimal)s.pop()));&lt;br /&gt;
          break;&lt;br /&gt;
        // - and /, order *does* matter&lt;br /&gt;
        case &amp;quot;-&amp;quot;:&lt;br /&gt;
          tmp = (BigDecimal)s.pop();&lt;br /&gt;
          s.push(((BigDecimal)s.pop()).subtract(tmp));&lt;br /&gt;
          break;&lt;br /&gt;
        case &amp;quot;/&amp;quot;:&lt;br /&gt;
          tmp = (BigDecimal)s.pop();&lt;br /&gt;
          s.push(((BigDecimal)s.pop()).divide(tmp,&lt;br /&gt;
            BigDecimal.ROUND_UP));&lt;br /&gt;
          break;&lt;br /&gt;
        default:&lt;br /&gt;
          throw new IllegalStateException(&amp;quot;Unknown OPERATOR popped&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
      } else {&lt;br /&gt;
        throw new IllegalArgumentException(&amp;quot;Syntax error in input&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return (BigDecimal)s.pop();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Big Integer demo ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.math.BigInteger;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2000 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book (recommended),&lt;br /&gt;
 * visit http://www.davidflanagan.ru/javaexamples2.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * This program computes and displays the factorial of a number specified on the&lt;br /&gt;
 * command line. It handles possible user input errors with try/catch.&lt;br /&gt;
 */&lt;br /&gt;
public class FactComputer {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Try to compute a factorial.&lt;br /&gt;
    // If something goes wrong, handle it in the catch clause below.&lt;br /&gt;
    try {&lt;br /&gt;
      int x = Integer.parseInt(args[0]);&lt;br /&gt;
      System.out.println(x + &amp;quot;! = &amp;quot; + Factorial4.factorial(x));&lt;br /&gt;
    }&lt;br /&gt;
    // The user forgot to specify an argument.&lt;br /&gt;
    // Thrown if args[0] is undefined.&lt;br /&gt;
    catch (ArrayIndexOutOfBoundsException e) {&lt;br /&gt;
      System.out.println(&amp;quot;You must specify an argument&amp;quot;);&lt;br /&gt;
      System.out.println(&amp;quot;Usage: java FactComputer &amp;lt;number&amp;gt;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    // The argument is not a number. Thrown by Integer.parseInt().&lt;br /&gt;
    catch (NumberFormatException e) {&lt;br /&gt;
      System.out.println(&amp;quot;The argument you specify must be an integer&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    // The argument is &amp;lt; 0. Thrown by Factorial4.factorial()&lt;br /&gt;
    catch (IllegalArgumentException e) {&lt;br /&gt;
      // Display the message sent by the factorial() method:&lt;br /&gt;
      System.out.println(&amp;quot;Bad argument: &amp;quot; + e.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/**&lt;br /&gt;
 * This version of the program uses arbitrary precision integers, so it does not&lt;br /&gt;
 * have an upper-bound on the values it can compute. It uses an ArrayList object&lt;br /&gt;
 * to cache computed values instead of a fixed-size array. An ArrayList is like&lt;br /&gt;
 * an array, but can grow to any size. The factorial() method is declared&lt;br /&gt;
 * &amp;quot;synchronized&amp;quot; so that it can be safely used in multi-threaded programs. Look&lt;br /&gt;
 * up java.math.BigInteger and java.util.ArrayList while studying this class.&lt;br /&gt;
 * Prior to Java 1.2, use Vector instead of ArrayList&lt;br /&gt;
 */&lt;br /&gt;
class Factorial4 {&lt;br /&gt;
  protected static ArrayList table = new ArrayList(); // create cache&lt;br /&gt;
  static { // Initialize the first element of the cache with !0 = 1.&lt;br /&gt;
    table.add(BigInteger.valueOf(1));&lt;br /&gt;
  }&lt;br /&gt;
  /** The factorial() method, using BigIntegers cached in a ArrayList */&lt;br /&gt;
  public static synchronized BigInteger factorial(int x) {&lt;br /&gt;
    if (x &amp;lt; 0)&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;x must be non-negative.&amp;quot;);&lt;br /&gt;
    for (int size = table.size(); size &amp;lt;= x; size++) {&lt;br /&gt;
      BigInteger lastfact = (BigInteger) table.get(size - 1);&lt;br /&gt;
      BigInteger nextfact = lastfact.multiply(BigInteger.valueOf(size));&lt;br /&gt;
      table.add(nextfact);&lt;br /&gt;
    }&lt;br /&gt;
    return (BigInteger) table.get(x);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * A simple main() method that we can use as a standalone test program for&lt;br /&gt;
   * our factorial() method.&lt;br /&gt;
   */&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    for (int i = 0; i &amp;lt;= 50; i++)&lt;br /&gt;
      System.out.println(i + &amp;quot;! = &amp;quot; + factorial(i));&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Demonstrate large numbers ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.math.*;&lt;br /&gt;
/**&lt;br /&gt;
 * Demonstrate large numbers.&lt;br /&gt;
 * @author Ian F. Darwin, http://www.darwinsys.ru/&lt;br /&gt;
 * @version $Id: BigNums.java,v 1.4 2004/02/09 03:33:56 ian Exp $&lt;br /&gt;
 */&lt;br /&gt;
public class BigNums {&lt;br /&gt;
  public static void main(String[] argv) {&lt;br /&gt;
    //+&lt;br /&gt;
    System.out.println(&amp;quot;Here&amp;quot;s Long.MAX_VALUE: &amp;quot; + Long.MAX_VALUE);&lt;br /&gt;
    BigInteger bInt = new BigInteger(&amp;quot;3419229223372036854775807&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;Here&amp;quot;s a bigger number: &amp;quot; + bInt);&lt;br /&gt;
    System.out.println(&amp;quot;Here it is as a double: &amp;quot; + bInt.doubleValue());&lt;br /&gt;
    //-&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>