Неверные типы операндов для двоичного оператора '>', использующего двойные - PullRequest
0 голосов
/ 09 января 2019

Итак, я получаю ошибку в методах findSmallest и findLargest, но я понимаю ошибку, я просто не понимаю, почему это происходит. Я сравниваю 2 двойных в двумерном массиве, но все еще говорит мне, что я не могу сравнить их с «>». Любая помощь будет принята с благодарностью. Вы можете пропустить большую часть основного метода в тех местах, где у меня есть проблемы.

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");
}
}

Понятия не имею, почему в этом случае возникает ошибка, но есть ли альтернативный способ сделать то, что я сделал?

1 Ответ

0 голосов
/ 09 января 2019

это двумерный массив, поэтому, когда вы делаете

diverScore[smallest] > diverScore[y]

вы сравниваете массивы, а не удваивается.

double[][] diverScore

Согласно вашему вводу

 for(int x = 0; x<diverScore.length; x++)        //
    for(int y = 0; y<diverScore[x].length; y++) //
        // here

Вам нужно сделать внутренний цикл

...