Topic: 关于Math.random()的问题

  Print this page

1.关于Math.random()的问题 Copy to clipboard
Posted by: careson919
Posted on: 2009-07-08 12:02

public class GroupScore {
  public static void main(String[] args) {
    int a,b,c,d,e,sum;
    a = (int)Math.random()*100;System.out.println("张三的成绩是: "+a);
    b = (int)(Math.random()*100);System.out.println("李四的成绩是: "+b);
    c = (int)(Math.random()*100);System.out.println("王五的成绩是: "+c);
    d = (int)(Math.random()*100);System.out.println("赵六的成绩是: "+d);
    e = (int)(Math.random()*100);System.out.println("朱七的成绩是: "+e);
    sum = a + b + c + d + e;
    
    if(a>=60&&b>=60&&c>=60&&d>=60&&e>=60&&sum/5>=80)
      System.out.println("团队通过测试!恭喜!");    
    else
     System.out.println("很遗憾,团队没有通过测试,继续努力!");  
  }
}

a = Math.random()*100 没有加括号,生成的随机数总是0,为什么?
请高手指点!!!

2.Re:关于Math.random()的问题 [Re: careson919] Copy to clipboard
Posted by: ivanna
Posted on: 2009-07-11 05:51

(int)操作 优于 运算 操作.
Math.random()<1
(int)Math.random() =0
0*100=0


   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