JusLip:
バスケットボールフリースローのパフォーマンスと割合のシミュレーション。コードは罰金を動作しますが、最後にまとめて印刷に私は最高スコアと5試合のうち最小スコアを報告する必要があります。+数(最大):出力がちょうど言う必要があり、「ベストゲームは無料なさをスローします」。そして、私はまた、最悪のゲームスコア(分)のために同じことをする必要があります。私は、この機能のようなものを取得する方法についての損失でループの結果を得るために作成された配列が、午前を持っている必要があると思います。
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!");
}
}
アービンド・クマールのAvinash:
次のように実行します。
import java.util.Scanner;
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;
int worst = Integer.MAX_VALUE, best = Integer.MIN_VALUE;
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 ");
}
}
worst = Math.min(worst, in);
best = Math.max(best, in);
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: " + best);
System.out.println("Worst Game Free Throws Made: " + worst);
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!");
}
}
テストの実行:
Enter Player's Free Throw Percentage: 60
Game 1:
OUT OUT IN IN OUT IN OUT IN IN OUT
Free Throws Made: 5 Out Of 10.
Game 2:
IN IN OUT IN OUT IN OUT IN OUT IN
Free Throws Made: 6 Out Of 10.
Game 3:
IN OUT IN IN IN OUT IN IN OUT OUT
Free Throws Made: 6 Out Of 10.
Game 4:
OUT IN IN IN IN OUT OUT IN IN IN
Free Throws Made: 7 Out Of 10.
Game 5:
IN IN IN IN OUT IN OUT OUT OUT OUT
Free Throws Made: 5 Out Of 10.
Summary:
Best Game Free Throws Made: 7
Worst Game Free Throws Made: 5
Total Free Throws Made: 29 Out Of 50
Average Free Throw Percentage: 58%
END OF SIMULATION!