用java写一段随机抽取3个人的代码

用java写一段随机抽取3个人的代码,第1张

用java.util.Radom类中的方法.

Random rd=new Random()

int persion_id=rd.nextInt(10)//这样可以得到0-10之间的一岩链敏个随机数(假如总共有十个粗枝学生.)

然后用,threeStudent.add(students[stu_id])实现唤孙.

有了这个以后,就好说了.循环取得三个学生.送到threeStudent中去.

public void chooseThree()

{

Random rd=new Random()

for(int i=0i<3i++)

{

threeStudent.add(students[stu_id])

}

}

祝你好运...

public class MouseEventDemo ... implements MouseListener {

        //where initialization occurs:

        //Register for mouse events on blankArea and the panel.

        blankArea.addMouseListener(this)

        addMouseListener(this)

    ...

    public void mousePressed(MouseEvent e) {

       saySomething("Mouse pressed # of clicks: "

                    + e.getClickCount(), e)

    }

    public void mouseReleased(MouseEvent e) {

       saySomething("Mouse released # of clicks: "

                    + e.getClickCount(), e)

    }

    public void mouseEntered(MouseEvent e) {

       saySomething("Mouse entered", e)

    }

    public void mouseExited(MouseEvent e) {

       saySomething("Mouse exited", e)

    }

   铅纤 public void mouseClicked(MouseEvent e) {

       saySomething("Mouse clicked (# of clicks: "

               早激帆     + e.getClickCount() + ")", e)

    }

    void saySomething(String eventDescription, MouseEvent e) {

        textArea.append(eventDescription + " detected on "

           陆雹             + e.getComponent().getClass().getName()

                        + "." + newline)

    }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12549655.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存