关于java中的随机数生成(波动) [英] About random numbers generation in java (swings)

查看:508
本文介绍了关于java中的随机数生成(波动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将一些随机数存储到一个数组中,然后在插入之前用该数组检查新生成的随机数,以便再次停止重复...........,

给出一些建议...............





i want store some random numbers into an array and newly generated random number checked with that array before insertion to stop repeeat again...........,
give some suggetions.............,


for(i=0;i<s;i++)>
    {
        if(ar[i]!=randomNumber)
        {
        str=Integer.toString(randomNumber);
        ta.setText(str);
        ar[i]=randomNumber;
        break;
        }
        else
        {
        JOptionPane.showMessageDialog(null,+count+"Already appeared"+randomNumber);
        count--;
        break;
        }





[torsten]添加了代码格式化[/ torsten]



[torsten]added code formating[/torsten]

推荐答案

以下是一些建议:

Here are some suggestions:

  • Work through some of the Tutorials[^].
  • Make use of the Documentation[^].
  • And specifically, use the Random class[^].


- 为什么 Integer.toString(String)

你可以使用一个简单的字符串数组。

TextArea无论如何都要取int值(如果确实需要添加 +给它使它成为一个字符串)



- 请更好地命名您的变量。当你使用更好的命名时,你将拥有更多的控制权,比如iRandom,oArray,oTextArea。



请具体说明你的问题。我们不提供家庭作业问题的代码。
- why Integer.toString(String) ?
You could use a simple String Array.
The TextArea will take the int value anyway (if really needed add + "" to it to make it a String)

- please name your variables better. You will have much more control when you use better namings, like "iRandom", "oArray", "oTextArea".

Please be specific with your question. we do not provide code for homework kind of problems.


这篇关于关于java中的随机数生成(波动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆