如题:请帮我解析这句int random = (int)(Math.random()*10)
再帮我写个关于抽奖中奖的小代码.用上这句指令,然后在代码请//标示
让我好理解!

解决方案 »

  1.   

    import java.io.BufferedReader; 
    import java.io.IOException; 
    import java.io.InputStreamReader; 
    public class test{ 
    public static void main(String args[]) throws NumberFormatException, IOException{ 
    int random = (int)(Math.random()*10) ;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
    int x=Integer.parseInt(br.readLine()); 
    if x>10||x<0 then 
    system.out.println("输入数据超出规定范围");
    else if x.equels(random) then
    system.out.println("你中奖了!");
    else
    system.out.println("请再接再厉!");
    end if
    }
    }
      

  2.   

    Math.random()方法是随机产生一个0-1之间的数.