小编use*_*589的帖子

Math.random打印出10个随机整数,但它们都是相同的数字?

在下面的程序中,使用时询问他想从哪个数字范围生成10个随机数,但是,一旦用户输入他的选择,打印的数字都是相同的?

import java.io.*;

public class RandomInt
{
    public static void main (String [] args) throws IOException
    {
        String inGuess;
        int theGuessInt = 0;
        int theNum;
        int theNum2;
        BufferedReader myInput = new BufferedReader (new InputStreamReader (
                System.in));
        System.out
                .println ("Hello this program generates random numbers from 0-10 or 20-30");
        System.out
                .println ("Please input '1' for the random generation of 0-10, or '2' for the generation of 20-30");
        inGuess = myInput.readLine ();
        theGuessInt = Integer.parseInt (inGuess);
        // Generate random numbers from 0 …
Run Code Online (Sandbox Code Playgroud)

java

-2
推荐指数
1
解决办法
1462
查看次数

标签 统计

java ×1