【发布时间】:2014-04-14 21:33:27
【问题描述】:
我一直在尝试解决这个问题,我对java的模块不是很流利,调用ref。有人可以帮我完成这个程序吗?这很令人困惑。 java中的引用传递存在很多问题,以及我在那里遇到的任何额外错误。我不断收到诸如不兼容类型之类的错误并且找不到符号。
//This program is designed to have the user enter 10 golf scores, then display them in ascending order.
import java.util.Scanner;
public class SortedGolfScoresMT
{
public static void main(String[] args)
{
//Declares the size for the variable, which is 10
int SIZE = 10;
//Declares the array and utilize it with SIZE variable
int[] scores = new int[SIZE];
getScores(scores, SIZE);
insertionSort(scores, SIZE);
displayScores(scores, SIZE);
}
public static int[] getScores(int scores[], int SIZE)
{
// Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//Declares the index as a counter
int index;
//Get the scores for each golf player
for ( index = 0; index <= SIZE - 1; index++)
{
System.out.print("Enter the golf scores for player " + (index + 1) + ": ");
scores[index] = keyboard.nextInt();
}
return scores[index];
}
public static int[] insertionSort(int array[], int SIZE)
{
int unsortedValue;
int scan;
int index;
for ( index = 1; index <= SIZE -1; index++)
{
unsortedValue = scores[index];
scan = index;
while (scan > 0 && array[scan - 1] < array[scan])
{
swapModule();
scan = scan - 1;
}
array[scan] = unsortedValue;
}
return array[scan];
}
public static int[] swapModule(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
return b;
}
public static int[] displayScores(int scores[], int SIZE)
{
int index;
System.out.print("The scores are now displayed: ");
for (index = 0; index <= SIZE - 1; index++)
{
System.out.print(scores[index]);
}
}
}
【问题讨论】:
-
编译器会告诉你准确哪一行哪一列是错的。请阅读它们并检查您做错了什么。
-
我仍在尝试找出如何解决每个错误。我不知道从哪个方向调试编译器告诉我的错误。
-
我给了你你想要的信息。你所要做的就是检查编译器的输出,它会告诉你哪一行有错误,在哪一列。阅读编译器输出,转到该行并检查您是否做错了什么
-
发布您从编译器获得的一些错误甚至是一个好主意。
-
其中一个错误显示“错误:不兼容的类型返回分数[索引]”,箭头指向索引左侧的第一个括号。第二个错误指出“找不到符号”关于“unsortedValue = scores[index]; 我认为第二个错误的问题之一是因为我没有完成第一个错误。但我尝试了很多方法并且还是不知道怎么解决第一个错误。
标签: java