Topic: 求救(模拟骰子&判断整数的级别)

  Print this page

1.求救(模拟骰子&判断整数的级别) Copy to clipboard
Posted by: cainiao025
Posted on: 2006-06-06 09:06

1.模拟一个骰子在连续一万次的投掷中,一至六点出现的次数。
2.用switch实现:输入一个整数,判断它的级别,A:90~100,B:80~90,c:70~80,D:60~70,E:0~59.

请各位大虾帮帮忙,遇到第一题是怎样想的,如何去实现它。

2.Re:求救(模拟骰子&判断整数的级别) [Re: cainiao025] Copy to clipboard
Posted by: why
Posted on: 2006-06-06 11:01

1. You may use java.util.Random's nextInt(int)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#nextInt(int)

2. A:90~100 B:80~90
Should 90 be A or B??
You may consider using 整数/10 or (整数-1)/10 in the switch statement

3.Re:求救 [Re: cainiao025] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-06-06 11:14

public class PitchDice {

  int PitchFlag = 10000;
  int PitchPoint = 0;
  int one = 0;
  int two = 0;
  int three = 0;
  int four = 0;
  int five = 0;
  int six = 0;
  
  public void Count(){
    while(PitchFlag>0){
      PitchPoint = (int)(Math.random()*6+1);
      switch(PitchPoint){
        case 1:
          one++;
          break;
        case 2:
          two++;
          break;
        case 3:
          three++;
          break;
        case 4:
          four++;
          break;
        case 5:
          five++;
          break;
        case 6:
          six++;
          break;
        default:
          break;
      }//End switch(...)
      PitchFlag--;
    }//End while(...)
    System.out.println("掷出一点的次数:"+one);
    System.out.println("掷出二点的次数:"+two);
    System.out.println("掷出三点的次数:"+three);
    System.out.println("掷出四点的次数:"+four);
    System.out.println("掷出五点的次数:"+five);
    System.out.println("掷出六点的次数:"+six);
  }
  
  public static void main(String args[]){
    PitchDice pd = new PitchDice();
    pd.Count();
  }
  
}

第二题自己做吧!

4.Re:求救(模拟骰子&判断整数的级别) [Re: cainiao025] Copy to clipboard
Posted by: cainiao025
Posted on: 2006-06-06 22:28

真是听君一席话,胜读十年书。多谢指教。兄的英文很了得喔。


   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