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 郭兴华 阅读(105) | 评论 (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 郭兴华 阅读(182) | 评论 (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 郭兴华 阅读(115) | 评论 (0)编辑 收藏
welcome.java

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

posted @ 2008-10-09 10:30 郭兴华 阅读(110) | 评论 (0)编辑 收藏
仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9