所以我介紹到Java的過程中,我應該創建一個使用數組,看起來像這樣一個簡單的高爾夫評分程序:高爾夫成績理貨程序的Java - 卡住
(我卡上時,底部它涉及到我所有的高爾夫球得分和統計陣列的結果......)
你打了多少洞? 9
Hole Pars
孔1的標準是什麼? 5
孔2的標準是什麼? 4
洞3的標準是什麼? 4
等
你的成績
你是怎麼在孔1拍? 4
你在洞2上射了什麼? 5
你在洞3上射了什麼? 3
等
你的得分摘要包括:
總數:帕
總孔一體:0
雙鷹總數(信天翁):0
鷹總數:0
總數小鳥的:5
總數收杆的:1
轉向架的總數:1
雙轉向架的總數:在孔的2
總數3個或更多高於標準桿:0
這是我不得不遠代碼,
/* Lab 4: Part 2 - Golf Score */
import java.io.*;
import java.text.*;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class golf_score2
{
public static void main(String[] args) throws IOException
{
Scanner m= new Scanner(System.in);
Scanner q= new Scanner(System.in);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("How many holes did you play?");
int h = m.nextInt();
int hArray[] = new int[h];
int pArray[] = new int[h];
// Asks the user to enter par for i number of holes
System.out.print("\nHole Pars");
for(int i=0;i <h;i++)
{
System.out.print("\n\nWhat is par for hole " + (i+1) + "? ");
hArray[i]=m.nextInt();
}
// Asks the user to enter score for i holes
System.out.print("\n\nYour Scores");
for(int i=0; i <h;i++)
{
System.out.print("\n\nWhat did you shoot on hole " + (i+1) + "? ");
pArray[i]=m.nextInt();
}
System.out.print("\n\n---------------------------");
System.out.print("\n\nYour scoring summary includes:");
score_result = pArray[i] - hArray[i];
System.out.print(score_result);
}
}
看看這個答案:http://stackoverflow.com/questions/24187709/getting-golf-scores-into-an-array?rq = 1使用2維數組。 – jsh
這是一個提示。這是對你的類的最後一部分的改變:'for(int i = 0; i
所以我認爲我爲「score_result」添加的最後一部分是完全錯誤的。我喜歡jsh所說的關於嘗試二維數組的問題,但我可能必須完全重新格式化我的代碼。基本上,每個洞的總得分應該是(洞洞分數 - 孔洞面值)。我想計算總數,我只是不知道是否有可能使用上面的代碼。有什麼建議麼? –