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 @ 2008-10-20 12:47 郭興華 閱讀(111) | 評論 (0)編輯 收藏
          java1.6省去了包裝類

          import java.util.*;
          public class BaoZhuang{
              public static void main(String[] args)
              {
                  Vector a=new Vector();
                  a.add("123");
                  a.add(244);
              }
          }
          這樣寫在1.4運行環境下,是不能通過的
          但在1.6運行環境下,卻可以。

          posted @ 2008-10-16 08:21 郭興華 閱讀(192) | 評論 (0)編輯 收藏
          測試自增、自減操作

          /*
          *測試自增、自減操作
          */
          public class SelfAction
          {
           public static void main(String[] args)
           {
            int x = 10;
            int a = x + x++;
            System.out.println("a=" + a);
            System.out.println("x=" + x);
            int b = x + ++x;
            System.out.println("b=" + b);
            System.out.println("x=" + x);
            int c = x + x--;
            System.out.println("c=" + c);
            System.out.println("x=" + x);
            int d = x + --x;
            System.out.println("d=" + d);
            System.out.println("x=" + x); 


           }
          }
          輸出 是
          a=20
          x=11
          b=23
          x=12
          c=24
          x=11
          d=21
          x=10

          posted @ 2008-10-13 07:06 郭興華 閱讀(123) | 評論 (0)編輯 收藏
          welcome.java

          public class Welcome
          {
            public static void main(String[] args)
            {
              System.out.println("這是你的第一個程序,歡迎你走入Java的大門");
            }
          }

          posted @ 2008-10-09 10:30 郭興華 閱讀(139) | 評論 (0)編輯 收藏
          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 
          主站蜘蛛池模板: 清原| 韩城市| 淳化县| 汾西县| 宁安市| 兴海县| 琼海市| 威海市| 邻水| 正宁县| 阳曲县| 滨海县| 平潭县| 溆浦县| 商南县| 朝阳市| 金华市| 连城县| 宁海县| 讷河市| 孙吴县| 涞水县| 阳曲县| 绿春县| 天门市| 尤溪县| 焉耆| 航空| 腾冲县| 和林格尔县| 泰宁县| 乌鲁木齐市| 大英县| 宣城市| 班玛县| 临城县| 莱州市| 衡东县| 陕西省| 大理市| 黄龙县|