Java 二进制运算符'&燃气轮机';使用双打
所以我在Java 二进制运算符'&燃气轮机';使用双打,java,jcreator,Java,Jcreator,所以我在findsmalest和findLargest方法中得到了错误,但是我理解错误,我只是不理解为什么会发生。我正在比较2D数组中的两个双精度,但它仍然告诉我不能将它们与'>'进行比较。任何帮助都将不胜感激。你可以跳过大部分的主要方法到我有问题的地方 import java.util.Scanner; public class DivingScores { public static void main(String[] args) { Scanner input = n
findsmalest
和findLargest
方法中得到了错误,但是我理解错误,我只是不理解为什么会发生。我正在比较2D数组中的两个双精度,但它仍然告诉我不能将它们与'>'进行比较。任何帮助都将不胜感激。你可以跳过大部分的主要方法到我有问题的地方
import java.util.Scanner;
public class DivingScores
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String[] judge = new String[7]; //
System.out.println("Enter judges' names:"); //
for(int x = 0; x<judge.length; x++) //
judge[x] = input.nextLine(); //
//
String[] diver = new String[4]; //
System.out.println("Enter divers' names:"); //
for(int x = 0; x<diver.length; x++) //
diver[x] = input.nextLine(); // Creating and Instantiating
//
double[] diveDifficulty = new double[7]; //
for(int x = 0; x<diveDifficulty.length; x++) //
diveDifficulty[x] = input.nextDouble(); //
//
double[][] diverScore = new double[4][7]; //
for(int x = 0; x<diverScore.length; x++) //
for(int y = 0; y<diverScore[x].length; y++) //
diverScore[x][y] = input.nextDouble(); //
System.out.println("Judges"); //
for(int x = 0; x<judge.length; x++) //
System.out.printf("%15s, ", judge[x]); //
System.out.println(); //
//
System.out.println("Divers"); //
for(int x = 0; x<diver.length; x++) //
System.out.printf("%13s, ",diver[x]); //
System.out.println(); //
//
System.out.println("Dive Difficulty"); // Printing
for(int x = 0; x<diveDifficulty.length; x++) //
System.out.printf("%2.2f, ", diveDifficulty[x]); //
System.out.println(); //
//
System.out.println("Diver Scores"); //
for(int x = 0; x<diverScore.length; x++) //
{ //
System.out.println(diver[x]); //
for(int y = 0; y<diverScore[x].length; y++) //
System.out.printf("%2.2f ", diverScore[x][y]); //
System.out.println(); //
}
findSmallest(diverScore);
findLargest(diverScore);
awardMedal(calcScore(diverScore, diveDifficulty, diver.length), diver);
}
public static void findSmallest(double[][] diverScore)
{
for(int x = 0; x<diverScore.length; x++)
{
int smallest = 0;
for(int y = 0; y<diverScore[x].length; y++)
{
if(y > 0 && diverScore[smallest] > diverScore[y]) //Error Here
smallest=y;
}
diverScore[x][smallest] = 0;
}
}
public static void findLargest(double[][] diverScore)
{
for(int x = 0; x<diverScore.length; x++)
{
int largest = 0;
for(int y = 0; y<diverScore[x].length; y++)
{
if(y > 0 && diverScore[largest] < diverScore[y]) //Error Here
largest=y;
}
diverScore[x][largest] = 0;
}
}
public static double[] calcScore(double[][] diverScore, double[] diveDifficulty, int divers)
{
double[] scores = new double[divers];
for(int x=0; x<divers; x++)
{
double total = 0;
for(int y=0;y<diverScore[x].length;y++)
total += diverScore[x][y]*diveDifficulty[y];
scores[x]=total;
}
return scores;
}
public static void awardMedal(double[] scores, String[] diver)
{
int first = 0;
int second = 0;
int third = 0;
for(int x = 0; x<scores.length; x++)
{
if(x!=0 && scores[first]<scores[x])
first = x;
}
System.out.println(diver[first] + scores[first] + " Gold");
scores[first]=0;
for(int x = 0; x<scores.length; x++)
{
if(x!=0 && scores[second]<scores[x])
second = x;
}
System.out.println(diver[second] + scores[second] + " Silver");
scores[second]=0;
for(int x = 0; x<scores.length; x++)
{
if(x!=0 && scores[third]<scores[x])
third = x;
}
System.out.println(diver[third] + scores[third] + " Bronze");
}
}
import java.util.Scanner;
公共类占卜核心
{
公共静态void main(字符串[]args)
{
扫描仪输入=新扫描仪(System.in);
String[]judge=新字符串[7]//
System.out.println(“输入法官姓名:”)//
对于(int x=0;x它是一个2D数组,所以当您执行
diverScore[smallest] > diverScore[y]
您正在比较数组,而不是双精度数组
double[][] diverScore
根据你的意见
for(int x = 0; x<diverScore.length; x++) //
for(int y = 0; y<diverScore[x].length; y++) //
// here
for(int x=0;xdouble[]diverScore
。当你说diverScore[minimable]>diverScore[y]
时,你试图比较两个double[]
(不是两个double
)。