Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于多线程的一道问题! [Re:zerog]
Stub





发贴: 8
积分: 0
于 2006-08-23 20:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
下面,是在下的试着写出的程序。在下也是个JAVA初学者,虽然有很多问题解绝不了,但这个问题还是很简单的。LZ请在自己试着写过程序之后,在来看看在下的代码。Don't be afraid to try.

欢迎对在下的代码提提意见^_^

public class TestRandomMath extends Thread
{
public static void main (String [] argv)
{
TestRandomMath t1 = new TestRandomMath();
TestRandomMath t2 = new TestRandomMath();
TestRandomMath t3 = new TestRandomMath();
t1.setPriority(Thread.MAX_PRIORITY);
t1.start();
t2.setPriority(Thread.MAX_PRIORITY);
t2.start();
t3.setPriority(Thread.MAX_PRIORITY);
t3.start();
}

private int random, one, two, three, four, five, six;

public void run()
{
for (int i = 0; i < 100; i++)
{
random = (int) (Math.random()*6+1);
switch (random)
{
case 1:
one = ++ one;
System.out.print(1);
break;
case 2:
two = ++ two;
System.out.print(2);
break;
case 3:
three = ++ three;
System.out.print(3);
break;
case 4:
four = ++ four;
System.out.print(4);
break;
case 5:
five = ++ five;
System.out.print(5);
break;
case 6:
six = ++ six;
System.out.print(6);
break;
}
}

System.out.println();
int sum = one+two+three+four+five+six;
System.out.println("总共得到了"+sum+"个");
System.out.println("出现1的概率为"+one+"%");
System.out.println("出现2的概率为"+two+"%");
System.out.println("出现3的概率为"+three+"%");
System.out.println("出现4的概率为"+four+"%");
System.out.println("出现5的概率为"+five+"%");
System.out.println("出现6的概率为"+six+"%");

}

}


why edited on 2006-08-24 08:56


话题树型展开
人气 标题 作者 字数 发贴时间
10027 关于多线程的一道问题! zerog 111 2006-08-23 10:51
8317 Re:关于多线程的一道问题! why 166 2006-08-23 19:41
8428 Re:关于多线程的一道问题! Stub 1734 2006-08-23 20:02
8476 Re:关于多线程的一道问题! colo007 101 2006-08-23 20:44
8235 Re:关于多线程的一道问题! why 112 2006-08-24 02:08
8239 Re:关于多线程的一道问题! d_ai_w_ei 34 2006-08-26 16:33
8833 Re:关于多线程的一道问题! zerog 1298 2006-08-30 23:29

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923