/* Big Math Factorial uses Java 1.1 BigInteger class to calculate factorial of any int. Calculates distribution of digits in the factorial and displays with 50 digits/line formatting. M. Gallant 02/14/2000 */ import java.awt.*; import java.applet.*; import java.util.*; import java.math.BigInteger; public class BigFactorial extends Applet { public TextArea textArea = new TextArea (15, 60); public TextField tf1 = new TextField("30",20 ) ; Button factorialn = new Button("Factorial!") ; Button clearbutton = new Button("Clear Text") ; public void init () { factorialn.setBackground(Color.red) ; add (clearbutton) ; add (tf1) ; add (factorialn) ; add (textArea); } public boolean action(Event evt, Object arg) { //intercept AWT action. if (evt.target == clearbutton) { textArea.setText("") ; return true ; } else if (evt.target == factorialn) { String num = tf1.getText() ; String res = getBigFactorial(num) ; if(res.charAt(0) == '!'){ textArea.setText(res) ; // bad format returned return true; } textArea.setText("----------- "+ num+"! (" + res.length() + " digits) ------------\n") ; textArea.append(findNumberDistribution(res)+"\n"); int index1 = 0; int index2 = 50 ; // display with 50 digits per line while(index21; j--) bnum = bnum.multiply(new BigInteger(String.valueOf(j))) ; return bnum.toString() ; } catch (NumberFormatException e) { return "!!!Bad number format !!!\n\n" ; } } public String findNumberDistribution(String instring) { int checksum=0 ; StringBuffer strbuff = new StringBuffer("Digit Count: ") ; for(int num=48; num<58; num++){ int numcount=0; for(int i=0; i