产生一个0到100的随机数,要求随机数大于50时抛出,用自定义异常帮一朋友问的,给出代码后,立刻送200分,谢谢

解决方案 »

  1.   

    public class TestClass {

    public static void main(String args[]) throws MyException
    {
        int random=(int)Math.random()*100;
        if(random>50)
            throw new MyException("The random number is more than 50.");
    }
    }class MyException extends Exception{
        MyException() {
            super();
        }
        MyException(String message) {
            super(message);
        }
    }
      

  2.   

    int random=(int)(Math.random()*100);
    这句修改一下,呵呵
      

  3.   

    呀呀呀。。
    jFresH_MaN(十一月的萧邦-夜曲) 5555~~~~~~~~ 慢了一步。
    package temp;import java.util.Random;public class Jf { public void demo() throws JfException {
    Random random = new Random();
    int ret = random.nextInt(100);
    System.out.println(ret);
    if (ret > 50) {
    throw new JfException("JF....");
    }
    }

    public static void main(String[] args) {
    try {
    (new Jf()).demo();
    } catch (JfException e) {
    e.printStackTrace();
    }
    }
    }class JfException extends Exception {

    public JfException(String x) {
    super(x);
    }
    }
      

  4.   

    OK,5/5 我在开一贴送100分,HeXuZhOnG(BT,思维中的战斗机) 和jFresH_MaN(十一月的萧邦-夜曲) (  领分