所以我介绍到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所说的关于尝试二维数组的问题,但我可能必须完全重新格式化我的代码。基本上,每个洞的总得分应该是(洞洞分数 - 孔洞面值)。我想计算总数,我只是不知道是否有可能使用上面的代码。有什么建议么? –