java技術博客

          jsp博客
          數據加載中……
          BigIntegerTest.java
          /*
          *用戶輸入兩個數字,程序將通知你中獎的機率有多大
          */
          import javax.swing.*;
          import java.math.*;
          public class BigIntegerTest{
          public static void main(String[] args){
          String input =JoptionPane.showInputDialog("請輸入彩球總數:");
          int n=Inter.parseInt(input);//將字符串轉化為整數
          /*中獎計算公式
          (n*(n-1)*(n-2)*...*(n-m+1))/(1*2*...*m)
          */
          BigInteger option =BigInteger.valueOf(1);
          for(int i=0;i<m;i++){
          option=option.multiply(BigInteger.valueOf(n-i)).divide(BigInteger.valueOf(i+1));}
          System.out.println("你的中獎機率為每" + option + "次中有一次!"); System.out.println("祝你好運!"); System.exit(0); }}

          posted on 2008-10-20 12:47 郭興華 閱讀(111) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 梧州市| 西乌珠穆沁旗| 修水县| 辽阳市| 哈尔滨市| 故城县| 科尔| 南平市| 常德市| 古浪县| 高邮市| 高要市| 钦州市| 得荣县| 丹寨县| 西畴县| 长沙市| 内乡县| 安丘市| 慈溪市| 黔南| 南充市| 通州市| 任丘市| 晴隆县| 渝北区| 方山县| 北流市| 镶黄旗| 乐都县| 江西省| 靖宇县| 兴仁县| 巴彦淖尔市| 海门市| 竹山县| 米脂县| 西城区| 桦川县| 同江市| 龙岩市|