gpt4 book ai didi

java - Java 中的随机数生成器

转载 作者:行者123 更新时间:2023-12-01 06:58:49 25 4
gpt4 key购买 nike

我正在编写一个像神奇的 8 球一样工作的程序。它会询问一个问题,然后打印出我输入的 20 个随机答案。它没有显示编码中的任何错误,但是当我运行它时,程序运行良好,直到需要打印随机响应为止。这是一项家庭作业,所以我不是在找人来纠正它,而是想弄清楚如何让它发挥作用。谢谢您,我很感谢您的帮助。

import java.util.Scanner;


public class MagicBall
{

public static void main(String[] args)
{

Scanner input = new Scanner(System.in);
System.out.println("Please type in a question: ");
double question = input.nextDouble();


int number = (int)(Math.random() * 20);

if (number == 0)
System.out.println("As I see it, yes");

if (number == 1)
System.out.println("It is certain");

if (number == 2)
System.out.println("It is decidedly so");

if (number == 3)
System.out.println("Most likely");

if (number == 4)
System.out.println("Outlook good");

if (number == 5)
System.out.println("Signs point to yes");

if (number == 6)
System.out.println("Without a doubt");

if (number == 7)
System.out.println("Yes");

if (number == 8)
System.out.println("Yes – definitely");

if (number == 9)
System.out.println("You may rely on it");

if (number == 10)
System.out.println("Reply hazy, try again");

if(number == 11)
System.out.println("Ask again later");

if (number == 12)
System.out.println("Better not tell you now");

if (number == 13)
System.out.println("Cannot predict now");

if (number == 14)
System.out.println("Concentrate and ask again");

if (number == 15)
System.out.println("Don't count on it");

if (number == 16)
System.out.println("My reply is no");

if (number == 17)
System.out.println("My sources say no");

if (number == 18)
System.out.println("Outlook not so good");

if (number == 19)
System.out.println("Very doubtful");
}
}

最佳答案

double question = input.nextDouble();

是什么让你认为问题是 float ?

关于java - Java 中的随机数生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com