gpt4 book ai didi

java - java中for循环的最小和最大结果

转载 作者:行者123 更新时间:2023-12-01 06:00:36 24 4
gpt4 key购买 nike

模拟篮球罚球表现和命中率。代码工作正常,但在最后的打印输出摘要中,我需要报告 5 场比赛的最高得分和最低得分。输出只需要说“最佳比赛罚球数:”+一个数字(最大值)。然后我还需要同样的东西来获得最差的游戏分数(分钟)。我想我需要从 for 循环结果创建一个数组,但我不知道如何获得这样的功能。

import java.util.*;

public class Final2 {
public static void main(String[] args){
int in = 0;
double total_in = 0;
int out;
int count = 0;
int games = 1;
int tries;
double average = 0;
int total = 0;

Scanner scan = new Scanner(System.in);
System.out.print("Enter Player's Free Throw Percentage: ");
int input = scan.nextInt();

do{
System.out.println("\nGame " + games + ":");
games++;

for (tries = 0; tries < 10; tries++){
int shot = (int)(Math.random()*100);
count++;


if (shot < input){
in++;
System.out.print("IN ");

}

else{
System.out.print("OUT ");
}
}
System.out.println("\nFree Throws Made: " + in + " Out Of 10. ");
total_in += in;
in = 0;
}
while (games <= 5);{
}
average = (total_in / count)*100;

System.out.println("\nSummary:");
System.out.println("Best Game Free Throws Made: " + "???");
System.out.println("Worst Game Free Throws Made: " + "???");
System.out.println("Total Free Throws Made: " + String.format("%.0f", total_in) + " Out Of " + count);
System.out.println("Average Free Throw Percentage: " + String.format("%.0f", average) + "%");
System.out.println("\nEND OF SIMULATION!");
}
}

最佳答案

不要想得这么复杂,作为一种帮助而不解决分配问题:考虑使用变量来表示最小值和最大值。

关于java - java中for循环的最小和最大结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60662732/

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