随机数生成器java

时间:2017-11-02 13:28:34

标签: java android random butterknife

我试图在android中创建一个基本的应用程序来感受android studio。我希望它在2个给定输入(高和低)之间产生一个随机数,并在最后5个列表中显示该数字。这是我现在的代码,因为它目前有效,它的设置和#39;低'达到上限。我已经暂时解决了这个问题并且无法得到答案。

例如:我使用10为低,20为高,最后5个数字为8,9,5,0和8。

编辑:根据pjs请求,我将代码缩短为必需品,然后再运行一些测试。我还在OnClick函数的高低之后添加了print语句,这是我的输出。

将低电平设置为10,将高电平设置为20输出 7系统中有7个用于高低, 3系统中有3个用于高低, 4个系统中有4个用于高低, 等。

public class MainActivity extends AppCompatActivity implements View.OnClickListener{


    /**
     * Create all instance variables
     */
    int high, low, r;
    ArrayList<Integer> numList = new ArrayList<>(5);
    boolean firstNum = true;
    Random random = new Random();

    /**
     * Bind the IDs made in the xml with the objects being used in main
     * using butterknife
     */
    @BindView(R.id.lowestNum) EditText min;
    @BindView(R.id.highestNum) EditText max;
    @BindView(R.id.currentRando) TextView rando;
    @BindView(R.id.randoList) TextView randoList;
    @OnClick (R.id.genBtn)

    /**
     * Generates the random number for the user
     * @param view
     */
    @OnClick(R.id.genBtn)
    public void onClick(View view) {
        high = Integer.parseInt(max.getText().toString());
        System.out.println(high);
        low = Integer.parseInt(min.getText().toString());
        System.out.println(low);
        r = random.nextInt(high - low + 1) + low;
        rando.setText("" + random);
        updateList(r);
        randoList.setText("" + listHelper(numList));
    }
}

提前致谢!

0 个答案:

没有答案
相关问题