gpt4 book ai didi

java - 如何重用输入值

转载 作者:行者123 更新时间:2023-12-01 17:16:38 25 4
gpt4 key购买 nike

public double getInput() {
System.out.print("Percentage of attacks that will be aimed low: ");
Scanner data = new Scanner(System.in);
double low = data.nextDouble();
return(low);
}


public static void main(String[] args) {
for ( int i = 0 ; i < round ; i++) {
xxxx.getInput();
}

我没有包含所有内容,但我希望您明白我的意思。

最佳答案

您不需要将 final 放在它前面,它将获取指定的第一个 int,并且因为它不在 for 循环,该值将永远改变,除非你自己改变它。但是,您尚未声明 low 的类型。所以这样做:

int low = data.nextInt();

从您的新代码中,您可以尝试以下操作:

public static void main(String[] args) {
Scanner data = new Scanner(System.in);
double low = data.nextDouble();
// you have low now
for ( int i = 0 ; i < round ; i++) {
System.out.print("Percentage of attacks that will be aimed low: ");
// do what you want with low
}

关于java - 如何重用输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21638579/

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